Hi,
I have a problem with this code I’m finishing up.
It works fine and uploads the image, but besides the image there are more fields and a submit button the client has to use. If the client uploads the image and then submits form with a few mistakes, it reloads the page asking him to fix errors.
However at this point the image field goes blank (although it has been loaded to database), and if the submit button is pressed again it will ask for an image again because this section of the code is run ( if($size==FALSE) echo “That’s not an image”)… despite the fact that the image was already loaded the first time.
How do make the code skip this section of the code ( if($size==FALSE) echo “That’s not an image”) once the submit button is hit?
Or how can I make the image stay there after submit button was pressed?
Hope I’m being clear. Appreciate any advice.
code:
<?php
//connect to databse
include ('connecthost.php');
//file properties
$file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo"Please select an image.";
else
{
//addslashes helps prevent sql injections
$image = @addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$size = @getimagesize($_FILES['image']['tmp_name']);
if($size==FALSE)
echo "That's not an image";
else
{
if (!$insert = mysql_query("INSERT INTO images VALUES ('','$image_name','$image')"))
echo"Problem uploading image";
else
{
$lastid = mysql_insert_id();
echo"Image uploaded.<p /> Your image:<p /><img src=getimage.php?id=$lastid height=\\"$height\\" width=\\"$width\\">";
}
}
}
?>