I love learning php but am fairly new at it. But I'm now reaching the end of my rope on this one...
Any help is appreciated
Code: Select all
<?php
# Setup SWFUpload Email Notify
# ---------------
$upload_email_reporting = true ; // true or false (false turns email reporting off)
$upload_notify_email = 'jonathan@bdglr.com' ;
$upload_directory = '' ; // leave blank for default
# PHP Email Configuration Test
# ---------------
# Set to "true" to test if your server's PHP mail() function configuration works, by attempting to upload one file.
# A simple email will be sent per upload attempt, letting you know PHP's mail() funciton is working.
$test_php_mail_config = false ; // true or false
# CREATE DEFAULT UPLOAD DIRECTY LOCATION
# ---------------
If ( !$upload_directory ) {
$upload_directory = 'uploads' ;
$parent_dir = array_pop(explode(DIRECTORY_SEPARATOR, dirname(__FILE__)));
$upload_directory = substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen($parent_dir) ) . $upload_directory ;
}
# ---------------
# EMAIL TESTS
If ( !$upload_notify_email ) {
$upload_email_reporting = true ;
}
# Sends one email per SWFUpload attempt.
if ( $test_php_mail_config == false ) {
send_mail("SWFUpload Email Test: SUCCESS!",'Be sure to set $test_php_mail_config back to false so that SWFUpload Email Notify reporting is turned on.');
$upload_email_reporting = false ;
}
# ---------------
# TEST UPLOAD DIRECTORY
If ( !file_exists($upload_directory) ) {
$msg = "The assigned SWFUpload directory, \"$upload_directory\" does not exist.";
send_mail("SWFUpload Directory Not Found: $upload_directory",$msg);
$upload_email_reporting = false ;
}
if ( $upload_email_reporting == true ) {
$uploadfile = $upload_directory. DIRECTORY_SEPARATOR . basename($_FILES['Filedata']['name']);
if ( !is_writable($upload_directory) ) {
$msg = "The directory, \"$upload_directory\" is not writable by PHP. Permissions must be changed to upload files.";
send_mail("SWFUpload Directory Unwritable: $upload_directory",$msg);
$upload_directory_writable = false ;
} else {
$upload_directory_writable = true ;
}
}
// Work-around for setting up a session because Flash Player doesn't send the cookies
if (isset($_POST["PHPSESSID"])) {
session_id($_POST["PHPSESSID"]);
}
session_start();
if ( !isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
# ---------------
# UPLOAD FAILURE REPORT
if ( $upload_email_reporting == true ) {
switch ($_FILES['Filedata']["error"]) {
case 1: $error_msg = 'File exceeded maximum server upload size of '.ini_get('2GB').'.'; break;
case 2: $error_msg = 'File exceeded maximum file size.'; break;
case 3: $error_msg = 'File only partially uploaded.'; break;
case 4: $error_msg = 'No file uploaded.'; break;
}
send_mail("SWFUpload Failure: ".$_FILES["Filedata"]["name"],'PHP Error: '.$error_msg."\n\n".'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true));
}
echo "There was a problem with the upload";
exit(0);
} else {
# ---------------
# COPY UPLOAD SUCCESS/FAILURE REPORT
if ( $upload_email_reporting == true AND $upload_directory_writable == true ) {
if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
send_mail("SWFUpload File Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true));
}else{
send_mail("SWFUpload File Not Saved: ".$_FILES["Filedata"]["name"],'Save Path: '.$uploadfile."\n\n".'$_FILES data: '."\n".print_r($_FILES,true));
}
}
echo "Flash requires that we output something or it won't fire the uploadSuccess event";
}
# ---------------
# MAIL FUNCTION
function send_mail($subject="Email Notify",$message="") {
global $upload_notify_email ;
$from = 'SWFUpload@mailinator.com' ;
$return_path = '-f '.$from ;
mail($upload_notify_email,$subject,$message,"From: $from\nX-Mailer: PHP/ . $phpversion()");
}
?>