Connecting Tech Pros Worldwide Forums | Help | Site Map

failed to open stream error with move_uploaded_file()

ifedi's Avatar
Member
 
Join Date: Jan 2008
Location: Abuja, Nigeria.
Posts: 46
#1: Aug 7 '08
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
  2.  
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.
Regards,
Ifedi.

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#2: Aug 7 '08

re: failed to open stream error with move_uploaded_file()


Hi.

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.
ifedi's Avatar
Member
 
Join Date: Jan 2008
Location: Abuja, Nigeria.
Posts: 46
#3: Aug 9 '08

re: failed to open stream error with move_uploaded_file()


thanks Atli for taking time to reply.

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

[PHP]
$available= is_writable($_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics/');
var_dump($available);
[/PHP]
Output: bool(false)

[PHP]
$available= is_writable($_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics'); //note absence of trailing forward slash
var_dump($available)[/PHP]
Output: bool(true)

The rest of the script panned out nicely afterwards:

[PHP]
$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics';

$uploadfile = $uploaddir .'/'.basename($_FILES['upload_pic']['name']);

if (move_uploaded_file($_FILES['upload_pic']['tmp_name'], $uploadfile)) {
$msg = "File is valid, and was successfully uploaded.";
} else {
$msg = "Error uploading!";
}
[/PHP]

Just thought I should 'epilogue' the post, for the possible benefit of some folk somewhere.

Regards,
Ifedi
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,748
#4: Aug 10 '08

re: failed to open stream error with move_uploaded_file()


Nice. Glad you found a solution.
And thanks for sharing it.
Reply