I am putting a file uploader in my site and it keeps failing at this move_uploaded_file() method. How can I figure out the specific error?

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload_path)) {
 ...
}
else {
  // how can I figure out why it failed?
}

Thanks!

    What is the PHP error message that is generated at that point?

      bradgrafelman;10981533 wrote:

      What is the PHP error message that is generated at that point?

      all I have there is

      echo "There was an error uploading the file

      That's the only information I get. I was hoping for an actual error. Something like maybe telling me the directory I am trying to move to doesn't exist or I don't have permission, you know, useful stuff.

      Thanks

        I've only been using PHP for about 2 days.. Is there some sort of error log or something?

          While samuelcook is right - you should be checking to see if the file was uploaded correctly before attempting to move said file - you should also ensure that display_errors is set to On (while developing; otherwise utilize log_errors instead) and error_reporting is set to E_ALL.

            definitely agree with brad.. something like:

            if($_FILES['userfile']['error']==0) {
              move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload_path);
            } else {
              // handle the error
            }
            

            additionally you may want to wrap the move_uploaded_file() in an if statement to ensure any error handling on that part.

              Write a Reply...