novicephp Posted October 21, 2008 Share Posted October 21, 2008 I picked a very simple one file + CSS file upload script and it looks so pretty that I want to stay with it. However I could do with it sending me an email once someone has uploaded a file. I have tried to Google for such script help but not found much I can understand. Is this a simple thing to add to the code below please. I would be most grateful if someone could show me how. Thanks <?php /************************************************* * Micro Upload * * Version: 0.1 * Date: 2006-10-27 * * Usage: * Set the uploadLocation variable to the directory * where you want to store the uploaded files. * Use the version which is relevenat to your server OS. * ****************************************************/ //Windows way $uploadLocation = "e:\domains\sensibleweb.co.uk\wwwroot\uploads\filestore\\"; //Unix, Linux way //$uploadLocation = "\filestore"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title></title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div id="caption">UPLOAD FILE</div> <div id="icon"> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data"> File to upload:<center> <table> <tr><td><input name="upfile" type="file" size="36"></td></tr> <tr><td align="center"><br/><input class="text" type="submit" name="submitBtn" value="Upload"></td></tr> </table></center> </form> <?php if (isset($_POST['submitBtn'])){ ?> <div id="caption">RESULT</div> <div id="icon2"> </div> <div id="result"> <table width="100%"> <?php $target_path = $uploadLocation . basename( $_FILES['upfile']['name']); if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { echo "The file: ". basename( $_FILES['upfile']['name']). " has been uploaded!"; } else{ echo "There was an error uploading the file, please try again!"; } ?> </table> </div> <?php } ?> </div> </body> Link to comment https://forums.phpfreaks.com/topic/129407-add-send-email-code-to-file-upload-script/ Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 try changing this: if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { echo "The file: ". basename( $_FILES['upfile']['name']). " has been uploaded!"; } else{ echo "There was an error uploading the file, please try again!"; } to if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) { $msg = "The file: ". basename( $_FILES['upfile']['name']) . " has been uploaded!"; mail('[email protected]','File uploaded - '.date('r'),$msg); echo $msg; } else{ echo "There was an error uploading the file, please try again!"; } Link to comment https://forums.phpfreaks.com/topic/129407-add-send-email-code-to-file-upload-script/#findComment-670917 Share on other sites More sharing options...
novicephp Posted October 21, 2008 Author Share Posted October 21, 2008 Thank you so much Aaron it worked a treat. I would never have worked that out. Regards Phil Link to comment https://forums.phpfreaks.com/topic/129407-add-send-email-code-to-file-upload-script/#findComment-670966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.