Can someone take a look at this code for me? I'm pretty new to programming,
but looking at it I think it should work. I'm not saying there aren't plenty
of errors, because I'm sure there are. I'm getting a parse error on the last
line, and I can't see any reason for it. All of my ifs and functions are
closed as far as I see. I guess I'm just looking for an unbiased eye here,
I've been staring at this for a couple hours now. If you have comments on to
how I could simplify this code, that'd be great too. Otherwise, I just need
it to get it working. Thanks in advance -
Jason Soza
------------------------------------
<?php
// general config
$timestamp = date("mdY");
$id = time();
$upload_path = "incoming/"; // path to your upload directory
$extval_use = 1; // turns on/off extension validation
// mail config
$xmailer = "[EMAIL PROTECTED]";
$xsender = "[EMAIL PROTECTED]";
$from = "[EMAIL PROTECTED]";
$to = "[EMAIL PROTECTED]";
$subject = "Form submission";
$boundary = "b".md5(uniqid(time()));
// form config
$name = $_POST["name"];
$email = $_POST["email"];
$location = $_POST["location"];
$color = $_POST["color"];
$year = $_POST["year"];
$misc = $_POST["misc"];
// extension config
$extval = array("php", "php3", "asp", "bat", "exe", "com", "jsp", "cfml",
"shtml", "dtcl");
$filesize_limit_use = 1; // turns on/off size check
$filesize_limit = 2048; // file size limit (in kB)
// messages
$message["fileisbig"] = "File is bigger than upload limit (" .
$filesize_limit . "kB)";
$message["invext"] = "Files of this type are not allowed, sorry.";
$message["incomplete"] = "Upload is incomplete.";
$message["complete"] = "Upload succesfully completed.";
$message["uploadbutton"] = "Upload";
$message["uploadtxt"] = "File for upload: ";
$message["fileexists"] = "File already exists";
// Define functions
function filesize_check ($filesize) {
if($filesize_limit < $filesize) {
echo "<p><font color='red'><center>"
. $message["fileisbig"]."</font></center></p>";
$rc = 1;
}
}
function ext_valid ($filename) {
$extget = substr( strrchr($filename, "."), 1);
$found = in_array($extget, $extval);
if ( $found ) {
echo "<p><font color='red'><center>"
. $message["invext"]."</font></center></p>";
$rc = 2;
}
function file_upload ($filename) {
if ( file_exists($upload_path.$timestamp."-".$id."-".$filename) ) {
echo "<p><font color='red'><center>"
. $message["fileexists"]."</font></center></p>";
} else {
if( move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'],
$upload_path.$timestamp."-".$id."-".$filename) ) {
echo "<p><center>" . $message["complete"]."</center></p>";
} else {
echo "<p><font color='red'><center>"
. $message["incomplete"]."</font></center></p>";
}
}
}
function filename_mod ($filename) {
ereg_replace("[^a-z0-9._]", "",
ereg_replace (" ", "_",
ereg_replace("%20", "_",
strtolower($orig_name))));
}
$rc = 0;
if($filesize_limit_use=1) {
$filesize1 = $HTTP_POST_FILES['userfile1']['name'] / 1024; //filesize
in kB
$filesize2 = $HTTP_POST_FILES['userfile2']['name'] / 1024; //filesize
in kB
$filesize3 = $HTTP_POST_FILES['userfile3']['name'] / 1024; //filesize
in kB
$filesize4 = $HTTP_POST_FILES['userfile4']['name'] / 1024; //filesize
in kB
}
if ( isset($HTTP_POST_VARS["upload"]) ) {
if ($HTTP_POST_FILES['userfile1']['name']) {
$orig_name1 = $HTTP_POST_FILES['userfile1']['name'];
$filename1 = filename_mod ($orig_name1);
filesize_check ($filesize1);
if ( $rc == 0 ) {
if($extval_use=1) {
ext_valid ($filename1);
}
}
if ( $rc == 0 ) {
file_upload ($filename1);
}
}
if ($HTTP_POST_FILES['userfile2']['name']) {
$orig_name2 = $HTTP_POST_FILES['userfile2']['name'];
$filename2 = filename_mod ($orig_name2);
filesize_check ($filesize2);
if ( $rc == 0 ) {
if($extval_use=1) {
ext_valid ($filename2);
}
}
if ( $rc == 0 ) {
file_upload ($filename2);
}
}
if ($HTTP_POST_FILES['userfile3']['name']) {
$orig_name3 = $HTTP_POST_FILES['userfile3']['name'];
$filename3 = filename_mod ($orig_name3);
filesize_check ($filesize3);
if ( $rc == 0 ) {
if($extval_use=1) {
ext_valid ($filename3);
}
}
if ( $rc == 0 ) {
file_upload ($filename3);
}
}
if ($HTTP_POST_FILES['userfile4']['name']) {
$orig_name4 = $HTTP_POST_FILES['userfile4']['name'];
$filename4 = filename_mod ($orig_name4);
filesize_check ($filesize4);
if ( $rc == 0 ) {
if($extval_use=1) {
ext_valid ($filename4);
}
}
if ( $rc == 0 ) {
file_upload ($filename4);
}
}
}
// Setup e-mail message
$body = "Date: $timestamp\n";
$body .= "Name: $name\n";
$body .= "E-mail: $email\n";
$body .= "Location: $location\n";
$body .= "Color: $color\n";
$body .= "Year: $year\n";
$body .= "Misc: $misc\n";
$body .= "File 1: $timestamp-$id-$filename1\n";
$body .= "File 2: $timestamp-$id-$filename2\n";
$body .= "File 3: $timestamp-$id-$filename3\n";
$body .= "File 4: $timestamp-$id-$filename4\n";
$mime = "From: $from\n";
$mime .= "Reply-To: $from\n";
$mime .= "X-Mailer: $xmailer\n";
$mime .= "X-Sender: $xsender\n";
$mime .= "Content-type: multipart/mixed; ";
$mime .= "boundary = $boundary\r\n\r\n";
$mime .= "This is a MIME encoded message.\r\n\r\n";
$mime .= "--$boundary\r\n";
$mime .= "Content-type: text/plain\r\n";
$mime .= "Content-Transfer-Encoding: base64";
$mime .= "\r\n\r\n".chunk_split(base64_encode($body))."\r\n";
// Send e-mail
mail ($to, $subject, "", $mime);
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php