Jump to content

Read File error


misslilbit02

Recommended Posts

Hi,

 

I'm trying to send an email from a form with an attachment but now I'm stuck because I'm getting this error:

 

PHP Warning: filesize() [function.filesize]: stat failed for C:\WINNT\TEMP\phpF53.tmp in D:\www\edu\Keiser Writes\submittal.php on line 54 PHP Warning: fread() [function.fread]: Length parameter must be greater than 0 in D:\www\edu\Keiser Writes\submittal.php on line 54

 

This is my code:

 

// Obtain file upload vars

$fileatt      = $_FILES['upfile']['tmp_name'];

$fileatt_type = $_FILES['upfile']['type'];

$fileatt_name = $_FILES['upfile']['name'];

 

$headers = "From: $email";

 

if (is_uploaded_file($fileatt)) {

  // Read the file to be attached ('rb' = read binary)

  $file = fopen($fileatt,'rb');

  //$data = file_get_contents($fileatt);

  $data = fread($file, filesize($fileatt));

  fclose($file);

 

Can someone help me with this matter? I don't know where to start with this. This code does work. I have a resellers hosting account I tested it on they are on the Lunix platform but at work I'm on the Windows platform and this does not work.

Link to comment
https://forums.phpfreaks.com/topic/59817-read-file-error/
Share on other sites

I no longer have the error. The temp directory wasn't defined in the php.ini file. The issue now is the email isn't sending. I did checks to see if the file uploaded and things of that nature and all seem well. It looks like things are getting stucks are the sending of the mail part.

 

// Generate a boundary string

  $semi_rand = md5(time());

  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

 

  // Add the headers for a file attachment

  $headers .= "\nMIME-Version: 1.0\n" .

              "Content-Type: multipart/mixed;\n" .

              " boundary=\"{$mime_boundary}\"";

 

  // Add a multipart boundary above the plain message

  $message = "This is a multi-part message in MIME format.\n\n" .

            "--{$mime_boundary}\n" .

            "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .

            "Content-Transfer-Encoding: 7bit\n\n" .

            $message . "\n\n";

 

 

echo $message;

 

  // Base64 encode the file data

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

 

  //echo $data;

 

  // Add file attachment to the message

  $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";

}

 

// Send the message

$ok = @mail($to, $subject, $message, $headers);

 

 

if ($ok) {

echo "<p>Mail sent! Yay PHP!</p>";

} else {

echo "<p>Mail could not be sent. Sorry!</p>";

?>

 

That is how the mailing portion looks courtesy of sitepoint but everytime it I submit the form it says mail could not be sent.

Link to comment
https://forums.phpfreaks.com/topic/59817-read-file-error/#findComment-297464
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.