Hi, There is a really simple answer to this, but for the life of me I cannot work it out. What I have is a script to upload images to a mysql databse which works like a dream. The problem I am having is that if a user does not select an image, no image is entered into the database, which cause issues when displaying on the site and also with updating the image a later time.
What I have been trying to do is if the userfile is left empty, on upload the php script selects an image of the server /admin/noimage.php and uploads that to the database.
Attached is the code snippet
I have tried now for ages... I just cannot do it and I am desperate for a little help.
Thank you very much in advance
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
if(!get_magic_quotes_gpc()) $fileName = addslashes($fileName);
$query='INSERT INTO timages (filename,size,type,width,height,content) VALUES ("'.$fileName.'","'.$fileSize.'","'.$fileType.'","'.$width.'","'.$height.'","'.$content.'")';
mysql_query($query,$dbh) or die(mysql_error());