View Single Post
Old Feb 13, 2005 | 04:31 PM
  #1  
Phil's Avatar
Phil
Jeebus
iTrader: (1)
 
Joined: May 2003
Posts: 8,663
Likes: 0
From: Staffordshire, UK
Default Anyone good with PHP? Quick question!

I have this code as part of a system inserting an image into a database:

$ffile = fopen($_FILES['image']['tmp_name'],"rb");
$contents = fread($ffile,$_FILES['image']['size']);
$eimage = mysql_escape_string($contents);
Now, if no image file is specified and the user hits submit this code produces an error obviously.

I'd normall just stick an if statement around it like this:

if ($image!="")
{
$ffile = fopen($_FILES['image']['tmp_name'],"rb");
$contents = fread($ffile,$_FILES['image']['size']);
$eimage = mysql_escape_string($contents);
}
But this seems to stop it from reading the image file ever - even if one is selected! What can I use in the if statement so that it works? Tried putting NULL in as well and that don't work!
Reply