Move_uploaded_file () could not open the stream: there is no such file or directory

I performed your standard checks (is there a directory there, fairly weak permissions are set), and I'm sure I covered your standard stupid human tricks. Here's the code that doesn't work:

move_uploaded_file($_FILES['image1']['tmp_name'], "/public_html/flashsale/assets/img/products/T".$_FILES['image1']['name']); 

There is a directory - I copied the path from FileZilla. I even set the permissions to 777 , both in FileZilla and in the file manager on the HostGator control panel. This code generates two warnings:

Message: move_uploaded_file (/public_html/flashsale/assets/img/products/Tsirloin.jpg) [function.move-uploaded-file]: could not open the stream: there is no such file or directory

Message: move_uploaded_file () [function.move-uploaded-file]: cannot execute move '/ tmp / phpI5GZ3S' to '/public_html/flashsale/assets/img/products/Tsirloin.jpg'

In that order. So, the file is uploaded, the directory exists and is set to 777, what else can I lose?

+8
php file-upload
source share
5 answers

you do not need to put the full directory in a file. try removing /public_html/flashsale/ from your link and see if this works. In addition, the file should not have permission 777, I myself upload the files to folders with 755 rights.

Alternatively, you can use getcwd(); in the directory you are aiming for. The function will provide you with the directory that you need to use to move your file. a source

+13
source share

Problem

 $dirpath = dirname(getcwd()) 

This is what I used initially to get the directory path to the / public _html / upload folder. $ dirpath will contain

 /public_html/upload 

Solution (on server)

 $dirpath = realpath(dirname(getcwd())) 

Since Im is in a shared hosting environment, the correct way to get move_uploaded_file to work, uses this as a destination: realpath (dirname (getcwd ())) returns something like:

 /home/cpanelusername/public_html/upload 
+5
source share

Make sure you go the way. public_html not required

 $image=basename($_FILES['file']['name']); $image=str_replace(' ','|',$image); $tmppath="images/".$image; if(move_uploaded_file($_FILES['file']['tmp_name'],$tmppath)) { echo "success"; } else { echo "fail"; } 

Hope this helps

+1
source share

For Ubuntu 14.04 with XAMPP, I also have boot problems, but after I fixed it with sudo chmod -R 777 destination , it works fine.

Here is what I did:

The temporary download folder in my Ubuntu 14.04 XAMPP is / opt / lampp / temp /. If I want my files to be loaded in /opt/lampp/temp/testupload as the destination folder, I need the configuration below.

  • Go to the temporary folder

     cd /opt/lampp/temp/ 
  • Create a folder 'testupload' in / opt / lampp / temp /

     sudo mkdir testupload 
  • Change Resolution 777

     sudo chmod -R 777 /opt/lampp/temp/testupload/ 
  • Php code

     move_uploaded_file($_FILES["file"]["tmp_name"], "/opt/lampp/temp/testupload/" . $_FILES["file"]["name"]) 
+1
source share

Solution for Windows and ISS:

The IUSR account requires permissions in the destination directory. Not the ISS_IUSR account, but only the IUSR account.

0
source share

All Articles