Forum Moderators: coopster

Message Too Old, No Replies

Attaching images to a form mail script

         

Ihatex86

8:34 pm on Mar 12, 2003 (gmt 0)

10+ Year Member



I have a client that sends me product images and incomplete descriptions randomly to add to his website. So i've decided to write a simple form mail script that will make sure that I have all the information for each product as well as images. I'm using the simple mail() function, however I'm unsure how to allow him to attach a file to the form and have it attached to the email I will recieve after he submits the data.

Anyone have a clue?

Thanks for your help in advance,
a php newb

jatar_k

3:04 am on Mar 14, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Ihatex86,

You could probably just have the form save the image to a directory on the site then you can put just the path in the email.

this is a really simple one

<form action="<?= $_SERVER['PHP_SELF']?>" enctype="multipart/form-data" method="post">
<table>
<tr>
<td colspan=2>Click on the Browse button below
<BR>then locate the file on your computer and press "Open".
<BR>Then press the submit button to upload the file.
<P>&nbsp;</td>
</tr>
<tr>
<td>File&nbsp;:&nbsp;</td>
<td><input name="file" type="file" /></td>
</tr>
<tr>
<td></td>
<td><input name="files" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
//this is the name of the directory the script will upload to
//this directory should be located in the same directory as the uploading script.
$dir = "dirname/";

if ($_POST["files"]) {
if (!file_exists($dir . $_FILES["file"]["name"])) {
copy($_FILES["file"]["tmp_name"], $dir . $_FILES["file"]["name"]);
$file = $_FILES["file"]["name"];
print("Your file has been uploaded.<br /><br />\n");
}

else {
print("Filename already exists.<br /><br />\n");
}
}
?>

then just put the filename $_FILES["file"]["name"] into your message then you can download the image at your leisure or link to it where it is.

Ihatex86

3:18 am on Mar 14, 2003 (gmt 0)

10+ Year Member



sweet! Thanks Jatar! I think this forum is going to be a great resource for expanding my understanding of PHP! :)