Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    Problem with file upload script

    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
    Code:
    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.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    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?"

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,107
    Thanks
    2
    Thanked 326 Times in 318 Posts
    From the error message, is there a folder /public_html/mysite/files/ where public_html is located in the disk root?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •