1

Any ideas why this isn't working? I've used it many times before. I have a folder called 'uploads' in the same directory

$target_path = "uploads/";
 $target_path = $target_path . basename( $_FILES['file']['name']); 

 if(! move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
  $error = 1;
 }

The file input form seems to be working, as when i echo out $_POST['file']; the file name is correct

Thanks

3
  • what's the exact problem? if the file isn't being moved, you should try to use an absolute $target_path (/.../.../uploads) instead of a relative one (uploads/). if upload is in the same dir as the php file you're working on, $target_path = basedir(__FILE__) . '/uploads/'; will work Commented May 10, 2010 at 17:36
  • move_uploaded_files is what throws the error, i tried using an absolute directory too, that didnt work? Commented May 10, 2010 at 17:43
  • Can you also post the error that you are getting? Commented May 10, 2010 at 17:46

3 Answers 3

2

Make sure that:

  • You have specified the encoding type enctype="multipart/form-data" in the form
  • The folder uploads has write permissions, chmod to 755
  • Try prefixing the path with $_SERVER['DOCUMENT_ROOT']
Sign up to request clarification or add additional context in comments.

Comments

0

Have you checked the permissions of the uploads folder? For uploads it usually needs permissions of 777 (Sometimes written as rwxrwxrwx), however I would try 755 or 775 first as there are security implications of allow full write access to global users.

Comments

0

Check if you have write privileges set to your uploads folder.

Comments

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.