Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form enctype="multipart/form-data" action="upload_file.php" method="POST">
- Choose a file to upload: <input name="uploaded" type="file" /><br />
- <input type="submit" value="Upload File" />
- </form>
- <?php
- $target = "upload/";
- $target = $target . basename( $_FILES['uploaded']['name']) ;
- $ok=1;
- $uploaded_type= $_FILES['uploaded']['type'];
- $uploaded_size= $_FILES['uploaded']['size'];
- //This is our size condition
- if ($uploaded_size > 350000)
- {
- echo "Your file is too large.<br>";
- $ok=0;
- }
- //This is our limit file type condition
- if ($uploaded_type =="text/php")
- {
- echo "No PHP files<br>";
- $ok=0;
- }
- //Here we check that $ok was not set to 0 by an error
- if ($ok==0)
- {
- Echo "Sorry your file was not uploaded";
- }
- //If everything is ok we try to upload it
- else
- {
- if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
- {
- echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
- }
- else
- {
- echo "Sorry, there was a problem uploading your file.";
- }
- }
- ?>
- echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
- echo '<pre>';
- print_r($_FILES);
- echo '<pre>';
- <?php
- if (TRUE) {
- echo '<pre>';
- print_r($_FILES);
- echo '<pre>';
- }
- $ok = TRUE;
- // Check if there is an uploaded file.
- if (!array_key_exists('uploaded', $_FILES) && !empty($_FILES['uploaded'])) {
- echo "Sorry, no file seems to be uploaded.";
- $ok = FALSE;
- }
- $target = "upload/";
- $target = $target . basename($_FILES['uploaded']['name']) ;
- $uploaded_type = $_FILES['uploaded']['type'];
- $uploaded_size = $_FILES['uploaded']['size'];
- // This is our size condition.
- if ($uploaded_size > 350000) {
- echo "Your file is too large.<br>";
- $ok = FALSE;
- }
- //This is our limit file type condition
- if ($uploaded_type =="text/php") {
- echo "No PHP files<br>";
- $ok = FALSE;
- }
- // Here we check that $ok was not set to 0 by an error
- if ($ok) {
- echo "Sorry your file was not uploaded";
- }
- // If everything is ok we try to upload it
- else {
- if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
- echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
- }
- else {
- echo "Sorry, there was a problem uploading your file.";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement