Page 1 of 1

If(isset) with $_FILES not working correctly

Posted: Sat Jun 16, 2007 8:59 am
by ianhull
hi Guys,

I have this

Code: Select all


if(isset($_FILES['logo']['tmp_name'])){
	$uploadedfile = $_FILES['logo']['tmp_name'];
	$src = imagecreatefromjpeg($uploadedfile);
	
	list($width,$height)=getimagesize($uploadedfile);
	move_uploaded_file($uploadedfile, "../logos/". strtolower(str_replace(" ", "-", $company_name. ' ' . $company_site.'_original.jpg')));
	
	$newwidth=30;
	$newheight=($height/$width)*30;
	$tmp=imagecreatetruecolor($newwidth,$newheight);
	
	imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 
	
	$filename = "../logos/". strtolower(str_replace(" ", "-", $company_name. ' ' . $company_site.'.jpg'));
	$logo = strtolower(str_replace(" ", "-", $company_name. ' ' . $company_site.'.jpg'));
	
	imagejpeg($tmp,$filename,100);
	
	imagedestroy($src);
	imagedestroy($tmp); 
	} else {	
	$logo = $_POST['original_logo'];
	};

but for some reason when I do not upload a new logo the code in the if part that is not meant to be executed is.

any ideas why?

on my form I have 1 hidden field call original_logo and another file field called logo

Thanks in advance.

thanks

Posted: Sat Jun 16, 2007 9:10 am
by volka
try

Code: Select all

echo '<pre>_FILES: '; var_export($_FILES); echo "</pre>\n";

if(isset($_FILES['logo']['tmp_name'])){
and take a look at the output.

Posted: Sat Jun 16, 2007 9:56 am
by ianhull
Thanks volka,

I got this returned

Code: Select all



_FILES: array (
  'logo' => 
  array (
    'name' => '',
    'type' => '',
    'tmp_name' => '',
    'error' => 4,
    'size' => 0,
  ),
)


How would I now setup the if/else to determine if the error happened?

Thanks in advance.

Posted: Sat Jun 16, 2007 10:00 am
by ianhull
i now managed to do it with

Code: Select all


if($_FILES['logo']['error'] == '4'){
	$logo = $_POST['original_logo'];
	} else {	
	$uploadedfile = $_FILES['logo']['tmp_name'];
	$src = imagecreatefromjpeg($uploadedfile);
	
	list($width,$height)=getimagesize($uploadedfile);
	move_uploaded_file($uploadedfile, "../logos/". strtolower(str_replace(" ", "-", $company_name. ' ' . $company_site.'_original.jpg')));
	
	$newwidth=30;
	$newheight=($height/$width)*30;
	$tmp=imagecreatetruecolor($newwidth,$newheight);
	
	imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 
	
	$filename = "../logos/". strtolower(str_replace(" ", "-", $company_name. ' ' . $company_site.'.jpg'));
	$logo = strtolower(str_replace(" ", "-", $company_name. ' ' . $company_site.'.jpg'));
	
	imagejpeg($tmp,$filename,100);
	
	imagedestroy($src);
	imagedestroy($tmp);
	};

thanks for your help.

Posted: Sat Jun 16, 2007 10:12 am
by feyd
You may want to have the file process only if it's error flag is zero.

Posted: Sat Jun 16, 2007 12:27 pm
by ianhull
Thanks for the tip feyd,

I have another issue,

This query does not seem to work with the WHEre clause, any one know why?

Thanks

Code: Select all


$result = mysql_query("SELECT count(*) FROM users WHERE company_name = '$company_name' AND company_site = '$company_site'");


Posted: Sat Jun 16, 2007 12:44 pm
by superdezign
I'd imagine that either the company_name or company_site column doesn't exist. Does it give you the error starting at the WHERE, or after it?

Posted: Sat Jun 16, 2007 12:46 pm
by volka
echo the query
and add error handling to your script, minimal version: mysql_query($query) or die(mysql_error());

Posted: Sat Jun 16, 2007 8:31 pm
by ianhull
The coumn definatley exists and the query works if do not use the WHERE clause.

There is no error returned if I error check the file

im confused.

Any ideas anyone?
Thanks

Posted: Sat Jun 16, 2007 9:40 pm
by superdezign
ianhull wrote:Any ideas anyone?
volka wrote:mysql_query($query) or die(mysql_error());
Tell us the exact error. It'll show you exactly what part of your WHERE clause is incorrect.