I have a basic form allowing text and an image upload, which works fine, adding text to a database and uploading the image to a folder. I'd like to add an option so that, if a user doesn't want to add an image, they can click a checkbox stating "No Image", i.e....
<b>Add an Image</b><br>
( File must be a .jpg or .gif extension only )<br>
<input type="file" name="upfile"> <p>
If no image, <input type=checkbox name=upfile value=no_image>Check this box
( I'm not sure what name or value to give the checkbox. )
Then, in the upload script, I have this, which gives the photo name ( 'upfile' ) a random name....
$max_size = 20000;
$filesize = $_FILES['upfile']['size'];
$filetype = $_FILES['upfile']['type'];
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/blah/blah/";
$photo = substr(sha1(rand(10, time())), 0, 8) . '.' . $file_types[$filetype];
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $upload_dir . $photo))
{
insert query.....
}
What I'm not sure of on this part is where/what to place in an if/else statement so that, if no image is uploaded, a default image name is inserted into the database ( i.e., "no_image.gif", determined by the checkbox? ). Either what I've tried has been put into the wrong place, written incorrectly, or both. Like I said, basic, but I guess I'm missing or overlooking something.