By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,900 Members | 1,370 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,900 IT Pros & Developers. It's quick & easy.

error :Email with attachment:move file upload :failed to open stream

P: 2
I have a main form for inputing the (to/from/mesg/file) with the following code:-
<td><input type="text" name="to" size="50"

<td><input type="text" name="from" size="50"></td>
<td><input type="text" name="subject"

<textarea cols="60" rows="5" name="message"
>Enter Your queries here</textarea>



id="upload" ENCTYPE="multipart/form-data"

Browse File<input type="file" id="abc" name="abc">
<input type="submit" name="upload" value="SEND


<input type="reset" value="Reset the form">


then I use theabove form to send the email with attachment: The next code first uploads to tmp dir on server and then sends the mail from the server.:-
$message ="file uploaded";

$temp_name = $_FILES['abc']['tmp_name'];
$file_name = $_FILES['abc']['name'];
$file_type = $_FILES['abc']['type'];
$file_size = $_FILES['abc']['size'];
$result = $_FILES['abc']['error'];

$upload_dir=$upDir . $temp_name;

//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
//File Size Check
else if ( $file_size > 500000) {
$message = "The file size is over 500K.";
return $message;
//File Type Check
else if ( $file_type == "text/plain" ) {
$message = "Sorry, You cannot upload any script

file" ;
return $message;



print $message;



$to = $_POST["to"];
$from = $_POST["from"];
$subject = $_POST["Subject"];

$fileatt = $upload_dir;

$fileatttype = "application/octet-stream";
$start= strrpos($fileatt, '/') == -1 ?

strrpos($fileatt, '//') : strrpos($fileatt, '/')+1;
$fileatt_name = substr($fileatt, $start,

strlen($fileatt)); // Filename that will be used

for the file as the attachment

$headers = "From: $from";



$file = fopen( $fileatt, 'rb' );
$data = fread( $file, filesize( $fileatt )

fclose( $file );


$semi_rand = md5( time() );
$mime_boundary =


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

multipart/mixed;\n" .


$message = "This is a multi-part message in

MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain;

charset=\"iso-8859-1\"\n" .

7bit\n\n" .
$message . "\n\n";

$data = chunk_split( base64_encode( $data )


$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n"

" name=\"{$fileattname}\"\n" .

attachment;\n" .
" filename=\"{$fileattname}\"\n" .

base64\n\n" .
$data . "\n\n" .



if( mail( $to, $subject, $message, $headers

) ) {

echo "<p>The email was sent.</p>";

else {

echo "<p>There was an error sending the




I get the error msg:move file upload /failed to open stream.
Kindly help in the coding.
Apr 28 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.