HB-
HB-

Reputation: 627

Why is PHP move_uploaded_file() failing to open stream?

I'm down to the most basic move and still struggling with it:

$path = '/home/*NAME*/public_html/ih/upload/';
$fileName = $_FILES["file"]["tmp_name"];

echo $path, "<br />"; echo $fileName;

move_uploaded_file($fileName, $path);

Both path and filename print the expected contents before the move fails. The path is identical to what I get when I echo getcwd() in the directory I want to move the files to. I've chmodded the upload folder and all subdirectories to 777 to be safe.

My error messages are:

Warning: move_uploaded_file(/home/*NAME*/public_html/ih/upload/) 
[function.move-uploaded-file]: failed to open stream: Is a directory in /home/*NAME*/public_html/ih/upload.php on line 11

Warning: move_uploaded_file() [function.move-uploaded-file]: 
Unable to move '/tmp/phph4oYFN' to '/home/*NAME*/public_html/ih/upload/' in /home/*NAME*/public_html/ih/upload.php on line 11

Does anyone know what I could do to fix this? Is it a permissions error? Thank you if so.

Upvotes: 0

Views: 166

Answers (1)

user1864610
user1864610

Reputation:

The clue is here:

[function.move-uploaded-file]: failed to open stream: Is a directory...

You've passed a directory path as an argument to move_uploaded_file(). You need to pass a filename.

Perhaps you want

move_uploaded_file($fileName, $path.$fileName);

This won't handle duplicate names well, though.

Upvotes: 3

Related Questions