This was generated through phpFormGenerator, but I'm getting the following warning message when a file is not uploaded. I didn't set it as a required field.
"Warning: copy() [function.copy]: Filename cannot be empty ..."
If it possible to skip this check since it's not supposed to be required to upload a file? I'm simply trying to make a contact form that emails basic information with the added option of attaching a file/picture.
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','FullName');
pt_register('POST','Email');
pt_register('POST','Phone');
pt_register('POST','QuestionsorComments');
$QuestionsorComments=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $QuestionsorComments);$AttachPictureforQuote=$HTTP_POST_FILES['AttachPictureforQuote'];
pt_register('POST','Howdidyoufindus');
if($FullName=="" || $Email=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name']==""){ }
else if(!is_uploaded_file($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['AttachPictureforQuote']['name'].", was not uploaded!";
$errors=1;
}
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$Email)){
$error.="<li>Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$image_part = date("h_i_s")."_".$HTTP_POST_FILES['AttachPictureforQuote']['name'];
$image_list[4] = $image_part;
copy($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'], "files/".$image_part);
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
$message="Full Name: ".$FullName."
Email: ".$Email."
Phone: ".$Phone."
Questions or Comments: ".$QuestionsorComments."
Attach Picture for Quote: ".$where_form_is."files/".$image_list[4]."
How did you find us: ".$Howdidyoufindus."
";
$message = stripslashes($message);
mail("webmaster@gmail.com","Form Submitted at your website",$message,"From: phpFormGenerator");
?>
<!-- This is the content of the Thank you page, be careful while changing it -->
<h2>Thank you!</h2>
<table width=50%>
<tr><td>Full Name: </td><td> <?php echo $FullName; ?> </td></tr>
<tr><td>Email: </td><td> <?php echo $Email; ?> </td></tr>
<tr><td>Phone: </td><td> <?php echo $Phone; ?> </td></tr>
<tr><td>Questions or Comments: </td><td> <?php echo $QuestionsorComments; ?> </td></tr>
<tr><td>Attach Picture for Quote: </td><td> <?php echo $AttachPictureforQuote; ?> </td></tr>
<tr><td>How did you find us: </td><td> <?php echo $Howdidyoufindus; ?> </td></tr>
</table>
<!-- Do not change anything below this line -->
<?php
}
?>
Thanks for your time and any help you can provide!