Jump to content

Probably can't be more basic! Warning: copy() [function.copy]: Filename cannot


lagvoid

Recommended Posts

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!

 

 

Link to comment
Share on other sites

if(isset($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name']))

{  copy($HTTP_POST_FILES['AttachPictureforQuote']['tmp_name'], "files/".$image_part);

}

 

Thank you for the quick response! isset still threw the warning, but is_null took care of it!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.