Page 1 of 1

move_uploaded_file() not working on production server -HELP!

Posted: Fri Jul 09, 2010 9:31 am
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...

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

Posted: Fri Jul 09, 2010 9:40 am
by agriz
Did you check the file uploading directory's permission?

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

Posted: Fri Jul 09, 2010 9:53 am
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?

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

Posted: Fri Jul 09, 2010 9:54 am
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";
	}


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

Posted: Fri Jul 09, 2010 10:02 am
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?

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

Posted: Fri Jul 09, 2010 10:07 am
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);

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

Posted: Fri Jul 09, 2010 10:11 am
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 ..

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

Posted: Fri Jul 09, 2010 10:22 am
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!

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

Posted: Fri Jul 09, 2010 10:27 am
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