PDA

View Full Version : making image upload an option


sticks
11-16-2002, 10:00 PM
Hi. I had a script made for adding a product to a database which includes linking to an image that is uploaded to a folder. This is all working well. Only thing is the script will not proceed if the user does not choose an image to upload. I want to make this a choice not a requirement. The relevant part of the code is below:-




if(isset($_FILES['files'])) {
if($_FILES['files']['type'] == 'image/gif' ||
$_FILES['files']['type'] == 'image/pjpeg' ||
$_FILES['files']['type'] == 'image/jpeg' ||
$_FILES['files']['type'] == 'image/jpg' &&
is_uploaded_file($_FILES['files']['tmp_name']) == true) {
move_uploaded_file($_FILES['files']['tmp_name'],'images/uploads/'. $_FILES['files']['name']);
$sql .= " ,imgname = '". DBUploadDir . $_FILES['files']['name'] . "'";
} else {
die('invalid image type. make sure your image type is a gif or jpeg. or the file is not a uploaded file.<br>
please use your back button and correct this.');
}
}




I was hoping someone could help with what I would need to do to make this an option. Thanking you, Sheryll.

firepages
11-17-2002, 02:28 AM
Hi, replace this ..


die('invalid image type. make sure your image type is a gif or jpeg. or the file is not a uploaded file.<br>please use your back button and correct this.');

for say

$noimg_comment="you did not upload any files"; //whatever//


Then later in your script you can <?echo $noimg_comment;?> if you want to.
Thing is ...not knowing what the rest of the script does its hard to say how that may affect it... i.e. this bit

$sql .= " ,imgname = '". DBUploadDir . $_FILES['files']['name'] . "'";

is qoing to be used later in the script and may kill the query, possibly not but just so you know, anyway its worth a try.

sticks
11-17-2002, 03:42 AM
Hi firepages. It worked and I'm wrapped so thank you very very much.

Sheryll :thumbsup: :thumbsup: