...

making image upload an option

sticks
11-15-2002, 09:59 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.

bcarl314
11-16-2002, 06:38 PM
This may be better for the php forum, but here's my guess,

If you're posting the form with an element name "files" even if the user doen't enter anything the variable "files" will be set, only it will be set to NULL or "". Add a check for those values.

ie

if(isset($_FILES['files']) && $_FILES!="") {


Hope this helps

sticks
11-16-2002, 09:57 PM
Thanks for your reply. I gave it a try but it didn't work so will post in php forum like you suggest.

Thanks, Sheryll.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum