hi

I have a form in which the "ADD attachment" field is optional.

I m sending this form information to email with file attachment as optional

if i dont upload/ attach any file then i get these below errors

vineet

Code:
Warning: fopen() [function.fopen]: Filename cannot be empty

Warning: fread() expects parameter 1 to be resource, boolean given

Warning: fclose() expects parameter 1 to be resource, boolean given
this is the script

PHP Code:
<?php

 
if(isset ($_POST["send"]))
 {
    
$upload_name=$_FILES["upload"]["name"];
    
$upload_type=$_FILES["upload"]["type"];
    
$upload_size=$_FILES["upload"]["size"];
    
$upload_temp=$_FILES["upload"]["tmp_name"];
    
$name=$_POST["name"];
    
$message=$_POST["msg"];
    
$subject $_POST["subject"];
    
$to="me@gmail.com";

    if(
$message==""||$subject==""||$name=="")
    {
        echo 
'<font style="font-family:Verdana, Arial; font-size:11px; color:#F3363F; font-weight:bold">Please fill name,subject,message</font>';
    }
    else
    {
    
$fp fopen($upload_temp"rb");
    
$file fread($fp$upload_size);
    
$file chunk_split(base64_encode($file));
    
$num md5(time());

        
// Attachment headers

        
$headers  .= "Content-Type:".$upload_type." ";
       
$headers  .= "name=\"".$upload_name."\"r\n";
       
$headers  .= "Content-Transfer-Encoding: base64\r\n";
       
$headers  .= "Content-Disposition: attachment; ";
       
$headers  .= "filename=\"".$upload_name."\"\r\n\n";
       
$headers  .= "".$file."\r\n";
       
$headers  .= "--".$num."--";

    
// SEND MAIL
       
@mail($to$subject$message$headers);
     
fclose($fp);
    echo 
'<font style="font-family:Verdana, Arial; font-size:11px; color:#333333; font-weight:bold">Mail sent please check inbox and spam both <br /></font>';
 }
 }
?>
<form id="attach" name="attach" method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>" enctype="multipart/form-data">
Name : <input type="text" name="name" id="name"><br>
Subject : <input type="text" name="subject" id="subject"><br>
Message : <input type="text" name="msg" id="msg"><br>
File Attach : <input type="file" name="upload" id="upload"> (Optional)<br>
               <input type="submit" value="Submit" id="send" name="send">
                </form>