PHP Warning: move_uploaded_file() unable to move


If you are new to PHP and just started learning the concepts, then definitely you’re gonna face this error once:

Warning: move_uploaded_file(upload/5c10de74dbb1b4.82572195.png): failed to open stream: No such file or directory in C:\wamp64\www\errortesting\invalid-foreach-argument.php on line 26

Warning: move_uploaded_file(): Unable to move ‘C:\wamp64\tmp\php505.tmp’ to ‘upload/5c10de74dbb1b4.82572195.png’ in C:\wamp64\www\errortesting\invalid-foreach-argument.php on line 26

When you try to upload any file or document through html form and php, you required that file to move physically to your destination folder.

PHP provides a function called move_uploaded_file(filename,destination) to move your uploaded file from temporary folder to required folder.

1st Parameter is a filename that is the temporary name of the file in $_FILES array.

2nd Parameter is a destination folder where you want the file to be moved. For ex, $destination = ‘uploads/new_filename’;

How the error is generated?

Look into the below case:

$file_tmp = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
$file_destination = 'upload/' . $file_name;
move_uploaded_file($file_tmp, $file_destination);

In above code snippet, I have used $_FILES array with the name of the input field that is “file” to get the name and temporary name of the uploaded file.

Check the scenario that cause the error:

  • Make sure you have created folder where you want to move your file.
  • Check for the folder permission, is it writable or not. Use chmod() to modify permission.
  • See if your target path URL is properly created or not. You can use dirname(__FILE__) to get the absolute path. To get current working directory, use getcwd().

Understand the basic requirement of the function and you will hardly face any error!

Hope this helps you. Best of luck for you code!


4 thoughts on “PHP Warning: move_uploaded_file() unable to move

  1. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to create my own blog and would like to know where u got this from. many thanks

  2. Please let me know if you’re looking for a article author for your site. You have some really good posts and I think I would be a good asset. If you ever want to take some of the load off, I’d really like to write some material for your blog in exchange for a link back to mine. Please blast me an e-mail if interested. Regards!|

Leave a Reply

Your email address will not be published. Required fields are marked *

Next Post

Warning: Cannot modify header information - headers already sent by

Tue Dec 25 , 2018
It’s very frustrating when you try to invent new code with your ability and errors just pop-up. I personally don’t like errors. But you know what is important in writing the code is? It’s a habit of keeping basic rules of writing code of any language (PHP, wordpress, drupal etc.) […]