PDA

View Full Version : PHP (uploading files and email confirmation)


chapt0r
Sat 11th May '02, 12:16am
Ok, I am sorry to bother again, (new to PHP) I got down the emailing script, and I even got down the File Uploading script to work, Now when I tried to combine the two, so when I recieve an email of a new submission it contains the file name that was loaded. This way in the email, I will know what images are related to what user. So far I am recieving this warning:

Warning: Undefined index: img1 in c:\program files\apache group\apache\htdocs\do_sendform.php on line 5

Here are the two sources:

HTML
<HTML>
<HEAD>
<TITLE>E-Mail Form</TITLE>
</HEAD>
<BODY>


<form enctype="multipart/form-data" method="post" action="do_sendform.php">


<P>Your Name:<br>
<INPUT type="text" name="sender_name" size=30>
</p>

<P>Your E-Mail Address:<br>
<INPUT type="text" name="sender_email" size=30>
</p>

<P>Message:<br>
<textarea name="message" cols=30 rows=5></textarea>
</p>

<input type="hidden" name="MAX_FILE_SIZE" value="50000">

<p><strong>File to Upload:</strong><br>

<INPUT type="file" name="img1" size"30"></p>


<INPUT type="submit" value="Send This Form">

</FORM>

</BODY>
</HTML>

PHP Is on next thread.

P.S. I have added the error_reporting = e_all & ~E_notice to my php.ini file.

Thanks again.

Wes

chapt0r
Sat 11th May '02, 12:18am
Here is the PHP,
If there is a better way of doing this, Please let me know and I will head in the learning direction of it. My main goal is to have a user upload a file along with txt, email, and this will be updated on a website. I do have Mysql in and all good to go with VB also. But I am working on the baby steps evolution of things. :) Thanks again.


<?

$msg = "Sender Name:\t$_POST[sender_name]\n";
$msg .= "Sender E-Mail:\t$_POST[sender_email]\n";
$msg .= "File Uploaded:\t$_POST[img1]\n";
$msg .= "Message:\t$_POST[message]\n\n";

$recipient = "creations@covad.net";
$subject = "Web Site Feedback";

$mailheaders = "From: My Web Site <> \n";
$mailheaders .= "Reply-To: $_POST[sender_email]\n\n";

mail($recipient, $subject, $msg, $mailheaders);

if ($img1_name != "") {
copy("$img1", "c:/uploads/$img1_name") or die("couldn't copy the file!");
}else{
die("No input file specified");
}

echo "<HTML><HEAD><TITLE>Form Sent!</TITLE></HEAD><BODY>";
echo "<H1 align=center>Thank You, $_POST[sender_name]</H1>";
echo "<P align=center>Your submission has been sent.</P>";
echo "</BODY></HTML>";


if ($img1_name != "") {
copy("$img1", "c:/uploads/$img1_name") or die("couldn't copy the file!");
}else{
die("No input file specified");
}
?>

scoutt
Mon 13th May '02, 1:15pm
if you are using php version 4.1.2 or higher than that won't work.


$msg .= "File Uploaded:\t$_POST[img1]\n";

needs to be

$msg .= "File Uploaded:\t$_FILE[img1][name]\n";

and this

if ($img1_name != "") {
copy("$img1", "c:/uploads/$img1_name") or die("couldn't copy the file!");
}else{
die("No input file specified");
}



needs to be

if ($_FILES['img1']['tmp_name'] != "none") {
copy("$_FILES['img1']['tmp_name']", "c:/uploads/".$_FILES['img1']['name']."") or die("couldn't copy the file!");
}else{
die("No input file specified");
}


agian look into super globals.