473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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

value="pras_sandilya@rediffmail.com"></td>
</tr>
<tr>
<td>From:</td>
<td><input type="text" name="from" size="50"></td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" name="subject"

size="50"></td>
</tr>
<tr>
<td>Message:</td>
<td>
<textarea cols="60" rows="5" name="message"
>Enter Your queries here</textarea>
</td>
</tr>
<td>

<form

action="http://www.urovisionhospital.com/ematt.php"

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

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

MAIL">
</form>



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

</table>
</body>
</html>



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.:-
<?php
$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'];



$upDir="/home/urovisio/tmp/";
$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;
}


if(move_uploaded_file($_FILES['abc']['tmp_name'],$u

pload_dir)){

print $message;
}





?>


<?php

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

?>


<?php

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

);
fclose( $file );

?>
<?php

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

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

$data = chunk_split( base64_encode( $data )

);

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

.
" name=\"{$fileattname}\"\n" .
"Content-Disposition:

attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding:

base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

?>


<?php

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

) ) {

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

}
else {

echo "<p>There was an error sending the

mail.</p>";

}


?>

I get the error msg:move file upload /failed to open stream.
Kindly help in the coding.
regards,
P.Sandilya
Apr 28 '07 #1
0 2460

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

Similar topics

0
by: BT | last post by:
Hi, I am trying to install php-mysql-4.0.6-7.i386.rpm(to get php to work with mysql as suggested for my earlier error). I get the following error for rpm -i php-mysql-4.0.6-7.i386.rpm. Error...
0
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a...
2
by: Zameer | last post by:
Hi All, I want to know how i can add attachment file to form for a particular user.Its like user fills his information on form and he can add an attachment file if he wants.And later when you...
1
by: Sebastian Mark | last post by:
Did anyone got error like that? When I'm trying to Update WebReference in my project this is an error I'm getting "Custom tool error: Failed to generate dataset. Undefined data type:...
0
by: Paul Urbanus | last post by:
Hi, I'm a perl hack and want to distribute a windows executable of one of my scripts. When I invoke the perl compiler by using perlcc, I get the following error. perlcc.bat: Can't unlink...
0
by: ASP Developer | last post by:
I recently changed the path of a virtual directory on my computer. After doing this I got an error in my solution stating that the web application could not be found. So I then copied all of the...
1
by: cainwebdesign | last post by:
php newbie needs help Warning: file(http://shop1.outpost.com/product/5053975) : failed to open stream: HTTP request failed! HTTP/1.1 404 Not Foundin I am just trying to put some code around...
1
by: =?Utf-8?B?VmFxdWFy?= | last post by:
Hi, Past few days I see following errors in Event Log after which few ASP scripts stopped working (or part of it's functionality - not very sure which one). "Error: File /trxweb/trxweb.asp ...
1
by: Justin | last post by:
When executing the command : db2fm -D I received the error: Failed to find the default instance. Environment variable $DB2INSTANCE not set properly. What is the best approach from here -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.