03-11-2010, 03:52 PM
|
#2 (permalink)
|
|
The Contributor
Join Date: Feb 2010
Posts: 69
Thanks: 16
|
well i have a similar script to what you are probably asking of... when a user uploads a file to the server i have it send me an e mail to tell me there has been a file put on the system.
just drop an e mail script at the bottom..
PHP Code:
//lets send the e mail with the data...
$to = "tim@tentun.co.uk";
$subject = "New template!";
$filename = str_replace(" ", "%20", $filename);
$body = 'New template has been uploaded by ' . $thename . ' E-Mail - ' . $themail . ' Template name - ' . $thetemplatename . ' URL - ' . $urlloc . $filename . '';
$headers = "From: tim@tentun.co.uk\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers)) {
echo("<p>A notification has been sent to the site and your template will be added ASAP!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
Thats just an example of my e mail message that should be sent.. my full layout is
PHP Code:
<?php
// Configuration - Your Options
$allowed_filetypes = array('.zip','.txt'); // These will be the types of file that will pass the validation.
$max_filesize = 2097152; // Maximum filesize in BYTES (currently 2MB).
$upload_path = '../uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// We'll start handling the upload in the next step
?>
<?php
// Configuration - Your Options
$allowed_filetypes = array('.zip','.txt'); // These will be the types of file that will pass the validation.
$max_filesize = 2097152; // Maximum filesize in BYTES (currently 2MB).
$upload_path = '../uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
$urlloc = 'http://www.tentun.co.uk/sb0t/uploads/';
$themail = $_REQUEST["email"];
$thename = $_REQUEST["yourname"];
$thetemplatename = $_REQUEST["templatename"];
$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
echo 'Your file upload was successful'; // It worked.
else
echo 'There was an error during the file upload. Please try again.'; // It failed :(.
//lets send the e mail with the data...
$to = "tim@tentun.co.uk";
$subject = "New template!";
$filename = str_replace(" ", "%20", $filename);
$body = 'New template has been uploaded by ' . $thename . ' E-Mail - ' . $themail . ' Template name - ' . $thetemplatename . ' URL - ' . $urlloc . $filename . '';
$headers = "From: tim@tentun.co.uk\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers)) {
echo("<p>A notification has been sent to the site and your template will be added ASAP!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
<?php
// refresh / redirect to an internal web page
// ------------------------------------------
header( 'refresh: 5; url=../index.php' );
echo '<h1>You will be re-directed in 5 seconds...</h1>';
?>
|
|
|
|