/    Sign up×
Community /Pin to ProfileBookmark

File reading error

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:WINNTTEMPphpF53.tmp in D:wwweduKeiser Writessubmittal.php on line 54 PHP Warning: fread() [function.fread]: Length parameter must be greater than 0 in D:wwweduKeiser Writessubmittal.php on line 54

[code=php]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);[/code]

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.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@misslilbit02authorJul 13.2007 — 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.

[code=php]// 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.0n" .
"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.nn" .
"--{$mime_boundary}n" .
"Content-Type: text/plain; charset="iso-8859-1"n" .
"Content-Transfer-Encoding: 7bitnn" .
$message . "nn";


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: base64nn" .
$data . "nn" .
"--{$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>";
}[/code]


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

Success!

Help @misslilbit02 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...