By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,068 Members | 867 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,068 IT Pros & Developers. It's quick & easy.

failed to open stream error with move_uploaded_file()

P: 60
In testing out a file upload script on my developer machine, I repeatedly came up with an error message. The goal was to upload pictures from a registration form into the folder 'clientpics' located somewhere within the htdocs (server) folder. Here's the message:

Expand|Select|Wrap|Line Numbers
  1. Warning:  move_uploaded_file(C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/doc/images/clientpics/nurses.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\doc\client_reg_page.php on line 25
Expand|Select|Wrap|Line Numbers
  1. Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Users\ifedi\AppData\Local\Temp\PHP\upload\php1C02.tmp' to 'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/doc/images/clientpics/nurses.jpg' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\doc\client_reg_page.php on line 25
Configuration: Windows Vista Home Premium running Apache with PHP and MySQL.
Actually, I'm practically convinced this has to do with Windows file permissions. Months ago, I had a similar headache, which I eventually was able to overcome by doing some editing on the sharing/permissions properties of the innermost directory (say 'clientpics') . This I did by following a step-by-step instruction I stumbled upon somewhere on the web. Unfortunately, that system was lost when the laptop got missing.
Now, I'm having to redo everything from scratch, and I really do need help here!
Finally, apologies for a rather lengthy post.
Aug 7 '08 #1
Share this Question
Share on Google+
4 Replies

Expert 5K+
P: 5,058

This doesn't seem to be a permission error tho. It's a "file not found" error.
Are you sure the directory you are using exists and that the path is spelled correctly?

Try using file_exists on the directory before you move the file, just to see if PHP can see it.
Aug 7 '08 #2

P: 60
thanks Atli for taking time to reply.

I ended up overcoming my problem when I stumbled on these results (which rather surprised little me!):

Expand|Select|Wrap|Line Numbers
  1. $available= is_writable($_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics/');
  2. var_dump($available);
Output: bool(false)

Expand|Select|Wrap|Line Numbers
  1. $available= is_writable($_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics'); //note absence of trailing forward slash
  2. var_dump($available)
Output: bool(true)

The rest of the script panned out nicely afterwards:

Expand|Select|Wrap|Line Numbers
  1. $uploaddir = $_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics';
  3. $uploadfile = $uploaddir .'/'.basename($_FILES['upload_pic']['name']);
  5. if (move_uploaded_file($_FILES['upload_pic']['tmp_name'], $uploadfile)) {
  6.    $msg = "File is valid, and was successfully uploaded.";
  7. } else {
  8.    $msg = "Error uploading!";
  9. }
Just thought I should 'epilogue' the post, for the possible benefit of some folk somewhere.

Aug 9 '08 #3

Expert 5K+
P: 5,058
Nice. Glad you found a solution.
And thanks for sharing it.
Aug 10 '08 #4

P: 1
thank you bro for sharing the solution
Feb 15 '20 #5

Post your reply

Sign in to post your reply or Sign up for a free account.