I have a form that gives the user an option to upload a file. The field is optional, but if they do not upload a file I would like to insert a default image into the database. At one point it was working but I can't seem to figure out what happened, here is the script:
if(isset($_FILES['fn'])){
$fn = $_FILES['fn']['name'];
//now try to upload the file
if(!move_uploaded_file($_FILES['fn']['tmp_name'],'../images/'.$_FILES['fn']['name'].'')){
switch($_FILES['fn']['error']){
case 1:
$msg .= "The file exceeds the upload max file size setting";
break;
case 2:
$msg .="The file exceeds the max file size setting";
break;
case 3:
$msg .="The file was only partially uploaded";
break;
case 4:
$msg .="No file was uploaded";
break;
}
if(isset($fn)){
$img = $fn;
}else{
$img = "user.gif";
}
The image upload works fine it just doesn't enter "user.gif" into the database if they do not upload a file. What it seems to me is happening is that if the user doesn't upload a file, the $img variable is never set, but I am not sure. I've tried several ways with no success.