Web Design Forum  
 
Go Back   Web Design Forum > Web and Graphic Design > Web Design

Reply
 
LinkBack Thread Tools Display Modes
Old 03-11-2009, 05:57 AM   #1
New Member
 
Join Date: Mar 2009
Posts: 2
Default Send E-mail When Uploading

Hello, I was just working on some coding. I was able to create an uploading form, where anyone who knows my web page can upload any form of media. However, I would like to know when someone does in fact upload something. Below is my code for the Browse and Submit functions. My question is: What would I add and where so that when someone uploads a file, I am sent an e-mail notification?

Thank you!


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data">
<table>
<tr><td><input name="upfile" type="file" size="36"></td></tr>
<tr><td align="center"><p><input class="text" type="submit" name="submitBtn" value="Upload" >


</p>
</td>
</tr>
</table></center>
</form>
<?php
if (isset($_POST['submitBtn'])){

?>
<div id="caption">Result:</div>
<div id="result">
<table width="100%">
<?php

$target_path = $_SERVER['DOCUMENT_ROOT'] . '/videos/' . basename( $_FILES['upfile']['name']);
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
echo "The file: ". basename( $_FILES['upfile']['name']).
" has been sucessfully uploaded.";
} else{
echo "There was an error uploading the file, but please try again.";
}
?>
</table>
</div>
<?php
}
?>
SBasis is offline   Reply With Quote


Old 03-11-2009, 10:55 PM   #2
Super Moderator
 
jnjc's Avatar
 
Join Date: Jun 2008
Posts: 493
Default

All you need to do is put a call to one of the php mail routines in your code:

Code:
$target_path = $_SERVER['DOCUMENT_ROOT'] . '/videos/' . basename( $_FILES['upfile']['name']);
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
echo "The file: ". basename( $_FILES['upfile']['name']).
" has been sucessfully uploaded.";

------  Insert mail code here ------

} else{
Do a google on phpmailer or something similar
jnjc is offline   Reply With Quote
Old 03-11-2009, 11:23 PM   #3
Gold Member
 
conor's Avatar
 
Join Date: Oct 2008
Location: Ireland
Posts: 349
Default

taken from http://ie2.php.net/mail

<?php

Code:
$Name = "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command :)
?>
__________________
Conor
conor is offline   Reply With Quote
Old 03-12-2009, 01:00 AM   #4
New Member
 
Join Date: Mar 2009
Posts: 2
Default Thank you

Thank you very much. It worked perfectly. I really appreciate it.
SBasis is offline   Reply With Quote
Reply

Tags
code, email, form, java, upload

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:18 AM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.