473,740 Members | 6,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

2 New Member
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_san dilya@rediffmai l.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.urovisionho spital.com/ematt.php"

id="upload" ENCTYPE="multip art/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=$up Dir . $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_uploade d_file($_FILES['abc']['tmp_name'],$u

pload_dir)){

print $message;
}





?>


<?php

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

$fileatt = $upload_dir;

$fileatttype = "applicatio n/octet-stream";
$start= strrpos($fileat t, '/') == -1 ?

strrpos($fileat t, '//') : strrpos($fileat t, '/')+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_Bo undary_x{$semi_ rand}x";

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

multipart/mixed;\n" .
"

boundary=\"{$mi me_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=\"{$fileat tname}\"\n" .
"Content-Disposition:

attachment;\n" .
" filename=\"{$fi leattname}\"\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 2489

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

Similar topics

0
2963
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 failed dependecies : libmysqlclient.so.10 is needed is needed by php-mysql-4.0.6-7.
0
2577
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 usercontrol into the place holder... i dont know why im getting this error:
2
2392
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 click on the User.His information along with the attachment should be displayed.
1
4516
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: 'anyType'." The anyType is really a GUID. The problem is its working fine on my friends computer (they get string insted of anyType) and it complies fine. I even tried to reinstall VS.NET 2003 but no positive result. Does anyone had that problem before?
0
3558
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 error file pccrYVGS If I try multiple times, the error is the same but the filename changes.
0
3120
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 files from the old location to the new location and the solution can now find the web application. However, now when I try to use "get latest version" I get the error: Unexpected error encountered. It is recommend that you restart the...
1
3068
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 this to trap it.
1
3581
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 Unexpected error. A trappable error (E06D7363) occurred in an external object. The script cannot continue running.." Source : Active Server Pages
1
4719
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 - Using option -i for instance ?
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8794
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9272
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9211
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3286
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.