I have a problem, do not want to get the file from the temporary folder ... This error occurs:

Warning: move_uploaded_file(/img/avatar/DSC00693.JPG) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/u141735831/public_html/edit_photo.php on line 9

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpM8N5wQ' to '/img/avatar/DSC00693.JPG' in /home/u141735831/public_html/edit_photo.php on line 9

Here is the handler code:

 <?php $uploads_dir = '/img/avatar'; $tmp_name = $_FILES["filename"]["tmp_name"]; $name = $_FILES["filename"]["name"]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); ?> 

    2 answers 2

    It is obvious that your script is in the root of the site, so most likely this is how:

     ... $uploads_dir = './img/avatar'; ... 
    • If the path starts with / then it is counted from the root of the file system.
    • If the path starts with ./ - then from the current folder
    • If with ../ - then from the folder to the next level

    And do not forget to set the +w rights for the uploading user to $uploads_dir , otherwise you will get Permission denied

    • Thank you, it helped) - Lgunchik

    Well, the first error clearly tells you that the folder in which you are trying to place the file is missing, or you just incorrectly entered its name or path to it. The second error appears in the result of the first.

    • No, the folder exists! - Lgunchik
    • Well, maybe you just typed in the name in lower case, and the folder name starts with a capital letter? Enter the name of the folder with the EXACT match of the register of its name. If you do everything right, then maybe you forgot to put "/" somewhere and as a result the file name merged with the path? - AseN
    • Do you go from the root of the FTP server? - AseN
    • the path fully corresponds to the one you need ... but this is why the error is ... mysite.ru/img/avatar/ - this is the path to the folder - Lgunchik
    • Can you show all the code from line one to line 15? So it will be easier to solve the problem. - AseN