Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload file thru form and attach to mail

Status
Not open for further replies.

dewang

Programmer
Jun 20, 2001
4
IN
Hi,
I am trying to upload a file using a form and attach the file to an email.
I have got a script that allows me to attach the file to the mail. The problem is with the uploaded file. When I try to access it using $HTTP_POST_FILES['drawing']['tmp_name'] I get an empty string.
The server is running PHP3. I have set the form enctype to multipart/form-data.
I would appreciate any help on what could be the problem and how to solve it.

Thanks,
Dewang
 
what gerrygerry said :) ***************************************
Party on, dudes!
[cannon]
 
Hi,
This is the code that looks for the uploaded file. I am using libmail to attach and send the mail. I would post that code, but its too long.
The basic problem is that it is not able to find the uploaded file. As mentioned in my first post, the server is running PHP3. The is_uploaded_file is not supported by the server since it must be running an older version of PHP3.
The form enctype is set to multipart/form-data and the name of the file field in the form is 'drawing'.
Code:
$mail = new Mail();  
$mail->From("webform@echjay.com");
$mail->To("dewangs@yahoo.com");
$mail->Subject("Website feedback");
$mail->Body($mtext);

//if (is_uploaded_file($HTTP_POST_FILES['drawing']['tmp_name']))
//{
	echo ("File name on server " . $HTTP_POST_FILES['drawing']['tmp_name']);
	echo ("File name on client " . $HTTP_POST_FILES['drawing']['name']);
	echo ("File name on client " . $HTTP_POST_FILES['drawing']);

	$attachment = $HTTP_POST_FILES['drawing']['tmp_name'];
	$mail->Attach($attachment);
//}
//else
//{
	echo("No file uploaded");
//}

$mail->Send();

Thanks again,
Dewang
 
$mail = new Mail();
$mail->From("webform@echjay.com");
$mail->To("dewangs@yahoo.com");
$mail->Subject("Website feedback");
$mail->Body($mtext);



if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
echo "
Temp name: $userfile <br>
Name: $userfile_name <br>
Size (Bytes): $userfile_size<br>
Type: $userfile_type <br>

&quot;;

$mail->Attach($userfile); // may be $userfile_name you'll need to try it as Im too tired to ;-)


}else{
echo(&quot;No file uploaded&quot;);
}
$mail->Send(); ***************************************
Party on, dudes!
[cannon]
 
Hi,
As I mentioned in my posts, the server is running PHP3. From what I read in the PHP manual. is_uploaded_file is available only in a later 3.0.something release.
Also the global vars $userfile are available only from PHP4. So the above code would not work on my PHP3 server.
Please correct me if I am wrong.
I am still looking for the solution to this problem.

Thanks,
Dewang
 
easy way to find the version stick a page in made of the following code:

<?
phpinfo();
?> ***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top