Jump to content

[SOLVED] Upload Default Pic


greenday

Recommended Posts

Hi, I am using a form to upload 5 image names to a database, and store the file in a folder. However, if only 4 or less of the five fields are filled out, the databases default image 'no image to display' is overwritten by nothing.

 

Is there any way to write an if field is blank, use default.gif file, else use uploaded file? Here is the code:

 

mysql_query("UPDATE `listtable` SET

`mainpic` = '".$_FILES['pic']['name'][0]."',

`pic2` = '".$_FILES['pic']['name'][1]."',

`pic3` = '".$_FILES['pic']['name'][2]."',

`pic4` = '".$_FILES['pic']['name'][3]."',

`pic5` = '".$_FILES['pic']['name'][4]."',

`pic6` = '".$_FILES['pic']['name'][5]."'

WHERE `placeid` = '$plid'");

 

Thanks.

Link to comment
Share on other sites

something like this perhaps - I only did it on pic 5 and 6 so you can see the diff..

 

$default = 'mypic.png';

mysql_query("UPDATE `listtable` SET
`mainpic` = '".$_FILES['pic']['name'][0]."',
`pic2` = '".$_FILES['pic']['name'][1]."',
`pic3` = '".$_FILES['pic']['name'][2]."',
`pic4` = '".$_FILES['pic']['name'][3]."',
`pic5` = '".( empty($_FILES['pic']['name'][4]) ? $default : $_FILES['pic']['name'][4] )."',
`pic6` = '".( empty($_FILES['pic']['name'][5]) ? $default : $_FILES['pic']['name'][5] )."'
WHERE `placeid` = '$plid'");

On another note, this is extremely insecure - crafted filenames could inject you sql - you really need to clean input and output!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.