I need a fresh set of eyes on this. I got this code from someone who said it worked.
Here is the error:
PHP Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\Inetpub\wwwroot\2am\employment\send-email-form.php on line 19
Line 19 is the first line of GetUploadedFileInfo()
. I get the error for line 20 and 21 also. Its obviously with the $file_info
array but whats wrong here?
Thanks in advance.
<?php
$max_allowed_file_size = "100"; // this is size in KB
list($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file) = GetUploadedFileInfo();
if(!Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size)) {
exit();
}
LoadUploadedFile($name_of_uploaded_file);
$path_of_uploaded_file = "uploads/" . $name_of_uploaded_file;
include_once('Mail.php');
include_once('mime.php');
ComposeMail($path_of_uploaded_file);
//////////////////// Functions ////////////////////////
function GetUploadedFileInfo() {
$file_info[] = basename($_FILES['uploaded_file']['name']);
$file_info[] = substr($file_info[0], strrpos($file_info[0], '.') + 1);
$file_info[] = $_FILES["uploaded_file"]["size"]/1024;
return $file_info;
}
function Validate($name_of_uploaded_file, $type_of_uploaded_file, $size_of_uploaded_file, $max_allowed_file_size) {
if($size_of_uploaded_file>$max_allowed_file_size ) {
echo "Size of file is greater than" . $max_allowed_file_size . " KB. <a href='attachment_email_form.html'>Click Here to upload a smaller sized file.</a>";
return false;
}
$allowed_extension = array("jpg", "jpeg", "gif", "bmp");
for($i=0; $i<sizeof($allowed_extension); $i++) {
$allowed_extension[$i] = strtoupper($allowed_extension[$i]);
}
$type_of_uploaded_file = strtoupper($type_of_uploaded_file);
if(!(in_array(strtoupper($type_of_uploaded_file),$allowed_extension))) {
echo "You have uploaded a file with an extension of " . $type_of_uploaded_file . " . This type is not allowed. Please upload a file with allowed image extensions like jpg, jpeg, bmp, gif. <a href='attachment_email_form.html'>Click Here to upload a file with allowed extension.</a>";
return false;
}
return true;
}
function LoadUploadedFile($name_of_uploaded_file) {
move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "uploads/" . $name_of_uploaded_file);
return true;
}
function ComposeMail($name_of_uploaded_file) {
$name = $_POST['name'];
$user_message = $_POST['message'];
$to = "[email protected]";
$subject="An email with attachement is sent";
$from = "[email protected]";
$text = "A user " . $name . "has sent you this message and an attachment: " . $user_message;
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($name_of_uploaded_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
echo "Your Email with attachment was sent.";
}
?>