move_uploaded_file() not working on production server -HELP!

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
mjsw
Forum Newbie
Posts: 10
Joined: Fri Jul 09, 2010 9:18 am

move_uploaded_file() not working on production server -HELP!

Post by mjsw »

Hello,

I'm facing very odd problem. I'm managing a .php site and recently we were forced to move from php 4.x or 5.0/1 (I'm not sure which was previous version :oops: ) to php 5.3 (this one I'm sure) and from 32 bit OS to 64 one. Scripts were runing as always, until I've tried to change the image of one of my products. The code looks like this:

Code: Select all

if(move_uploaded_file($_FILES['somefile']['tmp_name'],$uploaddir.$_FILES['somefile']['name']))
					{
						if($_FILES['somefile']['type']!="image/jpeg")
							if($_FILES['somefile']['type']!="image/pjpeg")
								if($_FILES['somefile']['type']!="image/png")
									if($_FILES['somefile']['type']!="image/gif") print("<br><b>File is not GIF, JPEG or PNG.&nbsp;</b>");
						$image=$_FILES['somefile']['name'];
						$ok=1;
					}
					else
					{
						$ok=0;
						print("<br><b><font color=\"red\">Can't load image!!</font></b><br>");
					}
What is more frustrating, on my dev machine also running php 5.3, this code executes well, so I never get into else (if image is valid of course). On the production server, I'm always ending inside the else, so I can't add the image :(

Any tips what is causing it and how to solve it?

Problem is this is happening on production environment so I can't do proper tests...
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: move_uploaded_file() not working on production server -H

Post by agriz »

Did you check the file uploading directory's permission?
mjsw
Forum Newbie
Posts: 10
Joined: Fri Jul 09, 2010 9:18 am

Re: move_uploaded_file() not working on production server -H

Post by mjsw »

Yes I just figured out that the problem is in writing rights. Although another odd thing: I can't set full write right for this folder :( They must have new policy regarding ftp access or I don't know what. How do you call CHMOD command not through ftp?
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: move_uploaded_file() not working on production server -H

Post by ScOrPi »

$uploaddir must be defined

$uploaddir = "upload/" . $_FILES['fileupload']['name'];

Check this out

Code: Select all

$uploaddir = "uploads/";
$fileext = $_FILES['somefile']['type'];
if (($fileext == "image/jpeg") || ($fileext == "image/pjpeg") || ($fileext == "image/png") || ($fileext == "image/gif")) {
	move_uploaded_file($_FILES['somefile']['tmp_name'],$uploaddir.$_FILES['somefile']['name']);
	$err = $_FILES['somefile']['error'];
	if ($err == 0) {
		echo "upload Done";
	}
	else
	{
		echo "There was a problem with uploading !";
	}
}
	else
	{
		echo "File Type doesn't Supported";
	}

Last edited by ScOrPi on Fri Jul 09, 2010 10:03 am, edited 1 time in total.
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: move_uploaded_file() not working on production server -H

Post by agriz »

Code: Select all

$uploaddir = "upload/" . $_FILES['fileupload']['name'];
I mean, here you are using "upload" directory to store files.
Did you check the "upload" directory's (chmod) permission. (right click upload directory in ftp software if you have, and click permissions)

It should have write access. It seems you have moved files from new os (64 bit).
Can you confirm this?
agriz
Forum Contributor
Posts: 106
Joined: Sun Nov 23, 2008 9:29 pm

Re: move_uploaded_file() not working on production server -H

Post by agriz »

mjsw wrote:Yes I just figured out that the problem is in writing rights. Although another odd thing: I can't set full write right for this folder :( They must have new policy regarding ftp access or I don't know what. How do you call CHMOD command not through ftp?

Code: Select all

chmod($uploaddir, 777);
After uploading,

Code: Select all

chmod($uploaddir, 644);
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: move_uploaded_file() not working on production server -H

Post by ScOrPi »

agriz wrote:
mjsw wrote:Yes I just figured out that the problem is in writing rights. Although another odd thing: I can't set full write right for this folder :( They must have new policy regarding ftp access or I don't know what. How do you call CHMOD command not through ftp?

Code: Select all

chmod($uploaddir, 777);
After uploading,

Code: Select all

chmod($uploaddir, 644);
he said that he is testing it on his machine .. i don't think that the cause from the permissions ..
mjsw
Forum Newbie
Posts: 10
Joined: Fri Jul 09, 2010 9:18 am

Re: move_uploaded_file() not working on production server -H

Post by mjsw »

OK I will try chmod then from php. Hope it will work...

directory is defined and it looks like

$uploaddir = "../categories/$cat_directory/";

again, $car_directory is defined.

Thanks for quick help guys!
ScOrPi
Forum Commoner
Posts: 44
Joined: Fri Jul 09, 2010 8:01 am
Location: BAGHDAD - IRAQ

Re: move_uploaded_file() not working on production server -H

Post by ScOrPi »

mjsw wrote:OK I will try chmod then from php. Hope it will work...

directory is defined and it looks like

$uploaddir = "../categories/$cat_directory/";

again, $car_directory is defined.

Thanks for quick help guys!
try it

$uploaddir = "../categories/".$cat_directory."/";

and be sure that $cat_directory doesn't end with "/"

and u welcome
Post Reply