View Full Version : Problem with file upload script

11-30-2008, 05:02 PM
I'm getting the following errors

Warning: move_uploaded_file(/public_html/mysite/files/13723491229.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/user/public_html/mysite/jobs/job_functions.php on line 157

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpDiNZef' to '/public_html/mysite/files/13723491229.gif' in /home/user/public_html/mysite/jobs/job_functions.php on line 157

everything is working fine except moving the file from the temp directory to the files directory.

I thought it was a permissions thing so i changed the permissions on folder "files" to 777. Still no luck.

This is my upload script....all functions in the background function properly

function uploadFile() {
if(checkFileProperties()) {
$extension = end(explode('.', strtolower(basename($_FILES[FILE_CTRL]['name']))));
$name = createFileName($extension,$_SESSION['uid']);
$newfilename = FILE_PATH . $name;
move_uploaded_file($_FILES[FILE_CTRL]['tmp_name'], $newfilename);
SaveFileToDB($_SESSION['uid'], $name);

} else {
$warningmessage = "ERROR: The file must be PDF or Gif format and be less than 4 mb";

any help is appreciated. Thanks in advance.

11-30-2008, 05:07 PM
This is a common problem and I can't remember what it was to fix it. But two suggestions you might try.

#1. Make sure your url to where to upload the file is 100% correct. Remember that uploaded and Uploaded are two different files.

#2. Make sure its not trying to upload a blank file, like the filename or something is incorrect, so it's saying "Hey I can't find the file?"

11-30-2008, 05:20 PM
From the error message, is there a folder /public_html/mysite/files/ where public_html is located in the disk root?

11-30-2008, 05:30 PM
Yes there is a folder in the path location. I cut and pasted from my server address bar into my script to make sure the path was correct.

I also ran file_exists($_FILES[FILE_CTRL]['tmp_name']) and it returns true. Seems to be the only problem is with either moving the file or the directory itself.

11-30-2008, 05:35 PM
I've got it now. All it takes is something stupid to make you feel like an idiot. The whole problem was i'm guessing the "scope" of the "files" directory. i just added "../" in front of "files/" and it worked perfectly.

i guess it doesn't work from the root directory but from the folder it is executing inside.