Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Any PHP Coding Experts Here?

New Here ,
Aug 08, 2011 Aug 08, 2011

I am attempting to get an online form with attachment working for a website. Upon submitting, I get the following errors:

Warning: filesize() [function.filesize]: stat failed for http://www.rockfordtoolcraft.com/sendresults.php in /home/xxxxxxx/public_html/sendresults.php on line 15

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /home/xxxxxxx/public_html/sendresults.php on line 15
The file was successfully sent!

I'd appreciate it very much if anyone can offer assistance with this code:

<?php 
$fileatt = "http://www.xxxxxxxxxxxxxxxxxxxx.com/sendresults.php";                 
$fileatt_type = "application/octet-stream";
$fileatt_name = "word file";

$email_from = "canidate";
$email_subject = "job inquiry";
$email_txt = "all about canidate";

$email_to = "xxxxxxxxxxxxx@xxxxxxxxxxxxxx.com";

$headers = "From: ".$email_from; 

$file = fopen($fileatt,'rb'); 
$data = fread($file,filesize($fileatt));
$size = ( $size > 1024 ? round($size/1024, 2) . "mb" : $size."kb"); 
fclose($file); 

$semi_rand = md5(time()); 
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
   
$headers .= "\nMIME-Version: 1.0\n" . 
            "Content-Type: multipart/mixed;\n" . 
            " boundary=\"{$mime_boundary}\""; 

$email_message .= "This is a multi-part message in MIME format.\n\n" . 
                "--{$mime_boundary}\n" . 
                "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
               "Content-Transfer-Encoding: 7bit\n\n" . 
$email_message . "\n\n"; 

$data = chunk_split(base64_encode($data)); 

$email_message .= "--{$mime_boundary}\n" . 
                  "Content-Type: {$fileatt_type};\n" . 
                  " name=\"{$fileatt_name}\"\n" . 
                  //"Content-Disposition: attachment;\n" . 
                  //" filename=\"{$fileatt_name}\"\n" . 
                  "Content-Transfer-Encoding: base64\n\n" . 
                 $data . "\n\n" . 
                  "--{$mime_boundary}--\n"; 

$ok = @mail($email_to, $email_subject, $email_message, $headers); 

if($ok) { 
echo "<font face=verdana size=2>The file was successfully sent!</font>"; 
} else { 
die("Sorry but the email could not be sent. Please go back and try again!"); 

?>

Thank you.

TOPICS
Server side applications
604
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 08, 2011 Aug 08, 2011

The second error with the fread is definitely caused by the first error.  Two things could be the root of the issue, first, are the permissions/ownership set correctly on the directory and the file that you are trying to access, and second what is the size of the file(s)?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 08, 2011 Aug 08, 2011
LATEST

I believe the directory is correct. The file is to be uploaded by the user.

I would like to restrict the file to be no larger than 500k.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines