problem with move_uploaded_file()?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mscardenas
Forum Newbie
Posts: 5
Joined: Wed May 30, 2007 1:18 am

problem with move_uploaded_file()?

Post by mscardenas »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all,

    I am uploading a file to the server with the code below.
. 
.

Code: Select all

if (is_uploaded_file($_FILES['upload_image']['tmp_name'])) 
	{
		if(move_uploaded_file($_FILES['upload_image']['tmp_name'], $target_path)) 
		{
			
			....codes
		} 
		else
		{
			echo("error: ".$_FILES['userfile']['error']);
	   		exit;//<----i always get here. Though the echo above just results in: error:   (blank -- no error?)
		}
	}
Problem is the temporary file can't seem to be moved from my server's temporary folder to the folder which I wanted the file to be saved, using move_uploaded_file.
I am assuming that my file has been uploaded, since $_FILES['upload_image']['tmp_name'] is not empty.
Also the $_FILES['userfile']['error'] is blank.
I also used the php function is_uploaded_file() to be sure that i have uploaded the file.
I have already checked the server's php.ini file, and everything seemed to be ok: file_uploads is "on", upload_max_filesize=2M, upload_tmp_dir = "no value".
$target_path == the location of my folder and my filename for the uploaded file, e.g. ../images/starcraft2.jpg
I have tested the code above before and it worked, don't know why it fails me now.

Help please??
Thanks.
Marc


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Guess that's server related because the upload file user is different from the php user ... and then is_uploaded_file() fails. Also move_uploaded_file() might not work or change file rights to 600, so you have to use copy() instead (even if checking is_uploaded_file() and move_uploaded_file() is the right/secure way).

djot
-
mscardenas
Forum Newbie
Posts: 5
Joined: Wed May 30, 2007 1:18 am

Post by mscardenas »

Ei thanks djot.:)

I also tried:

is_uploaded_file($_FILES['upload_image']['tmp_name']);
exit();

just to see if the page would show any error. But the page is just blank, not even a mention like "couldn't move to...permission error..etc"

So does this mean that the Temp directory (folder) where the temporary files are being put first have permissions too? And I can't move those temporary files using move_uploaded_file() because of the folder's permissions? So basically the problem is with the server?


Thanks.
Marc
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You have references to two differing uploads: $_FILES['upload_image'] and $_FILES['userfile']. Which one is correct?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

feyd wrote:You have references to two differing uploads: $_FILES['upload_image'] and $_FILES['userfile']. Which one is correct?
Yeah, that's why you're not getting an error message.


In all likeliness, $target_path doesn't have the correct permissions.
mscardenas
Forum Newbie
Posts: 5
Joined: Wed May 30, 2007 1:18 am

Post by mscardenas »

ops. sorry there.:D
$_FILES['userfile'] should be $_FILES['upload_image']. Copied it by mistake.:) Anyway, i still get the same response -- nothing. Not even any error messages for me to work on.

Thanks superdezign! you're right. The target path didn't have the correct permissions, I haven't thought about it before. The permission of the folder was 775, I can edit, delete, and upload files directly to it, so I never thought that my uploaded file through the form upload would have any problem with permissions. I asked our web admin to change the folder permission to 777 and my file upload worked!:D So it seemed that if I upload my files through a form, the webserver treats it as "others" and since permission 775 do not allow such user to write files, I was unable to move the files to that folder.

Thanks all! for the help.:D
Post Reply