0

I can't upload my PDF file, even I have tried some tips from google. But, My php upload still not work. I have changed the folder permission to 777.

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="3500000" />
Upload File: <input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>

$target_path = "/home/jeinqa/www/apps/upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
                }
        else{
                echo "There was an error uploading the file, please try again!";
                }

show : There was an error uploading the file, please try again!


try to use print_r($_FILES); :

Array ( [uploadedfile] => Array ( [name] => SOP-31 KW-HDR81BTJD.pdf [type] => [tmp_name] => [error] => 2 [size] => 0 ) ) There was an error uploading the file, please try again!
6
  • Any error messages you would like to share? It's impossible to help you with the provided info. This "question" just states: "it doesn't work, hallup" Commented Dec 5, 2012 at 9:32
  • Which echo from if(move_uploaded_file part gets into count? Commented Dec 5, 2012 at 9:33
  • write 2 echos, one for the target_path, one for $_FILES['uploadedfile']['tmp_name'], are they ok? Commented Dec 5, 2012 at 9:33
  • I'm copy this script from some tutorial sites.So,this is the 1st time I'm using this php upload. Commented Dec 5, 2012 at 9:35
  • are you sure that your file is < 10KB ? And you didn't use that max file size anywhere Commented Dec 5, 2012 at 9:35

1 Answer 1

1
  1. Does your folder has 777 permission (and all sub-folders)?
  2. Do you have safe_mode enabled in PHP.ini?
  3. Your MAX_FILE_SIZE is 10 KB but I doubt your file is this small please check your file size.
  4. Does the target_path exists?
  5. Try changing your target_path from absolute to relative it will probably become: upload.

Update

Your file is to big! Just change the max size! See http://php.net/manual/en/features.file-upload.errors.php for more information.

Your error: Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

Sign up to request clarification or add additional context in comments.

3 Comments

is that better if I not mention MAX FILE?
I don't think it matters any simple programmer can just inject another value in MAX_FILE_SIZE. I suggest checking the file_size with PHP. So yes you can remove the input field: <input type="hidden" name="MAX_FILE_SIZE" value="3500000" />
thank for your advise, after try step no 1 & 5 and delete MAX_FILE all can work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.