Hi all,
I am lees than new to php and wrote 2 seperate php files for a form on my website. One file was a general sendmail.php which formatted the form inputs into a legible email. The second was a file_upload.php file that uploaded a single file to a target directory on my server and renamed the file to CLIENT_PROJECT_FILENAME_INCREMENT.EXTENSION so no dupe files would exist. When tested the two forms worked individually. However when I combined them into a single sendmail.php file, the rename and upload_file functions do not work at all. No errors are being displayed. The Form simply emails me the correctly formatted answers to my form questions, but does not upload the attached file and thus does not rename said file as planned.
A link to a simplified form is here:
The underlying sendmail.php form is here:
<?php
$project = $_REQUEST['project'] ;
$project_other = $_REQUEST['project_other'] ;
$quantity = $_REQUEST['quantity'] ;
$pages = $_REQUEST['pages'] ;
$color = $_REQUEST['color'] ;
$color_other = $_REQUEST['color_other'] ;
$size = $_REQUEST['size'] ;
$page_layout = $_REQUEST['page_layout'] ;
$stock = $_REQUEST['stock'] ;
$stock_other = $_REQUEST['stock_other'] ;
$paper_finish = $_REQUEST['paper_finish'] ;
$paper_finish_other = $_REQUEST['paper_finish_other'] ;
$typeset = $_REQUEST['typeset'] ;
$timeframe = $_REQUEST['timeframe'] ;
$budget = $_REQUEST['budget'] ;
$add_info = $_REQUEST['add_info'] ;
$name = $_REQUEST['name'] ;
$phone = $_REQUEST['phone'] ;
$email = $_REQUEST['email'] ;
$company = $_REQUEST['company'] ;
$proj_name = $_REQUEST['proj_name'] ;
$zip = $_REQUEST['zip'] ;
$upload = $_REQUEST['upload'] ;
if (!isset($_REQUEST['email'])) {
header( "Location: ../pages/quote/quote.html" );
}
if ( ereg( "[\\r\
]", $name ) || ereg( "[\\r\
]", $email ) ) {
header( "Location: ../pages/quote/quote_injection_error.html" );
}
elseif (empty($name) || empty($phone) || empty($email) || empty($company) || empty($proj_name) || empty($zip) || empty($project) || empty($quantity) || empty($color) || empty($size) || empty($timeframe) || empty($budget)) {
header( "Location: ../pages/quote/quote_content_error.html" );
}
else {
mail( "QUOTES@DOMAIN.com", "Request for Quote: $project",
"$add_info\
What kind of project is this? $project\
Name: $name\
Name of Project: $proj_name\
Company: $company\
Telephone: $phone\
E-mail Address: $email\
ZIP code: $zip\
Is there a file attachment/upload? $upload\
What do you need a quote on? $project : $project_other\
What quantity do you require? $quantity\
If applicable, how many pages is each document? $pages\
Full color or black and white? $color : $color_other\
What size do you want your print project to be? $size\
What type of page layout do you need for your project? $page_layout\
What paper stock do you require? $stock : $stock_other\
What paper finish do you require? $paper_finish : $paper_finish_other\
Are your documents typeset? $typeset\
When do you need this project completed by? $timeframe\
What is your budget for this project? $budget\
Additional information to help COMPANY prepare our quote for you? $add_info",
"From: $name <$email>" );
header( "Location: ../pages/quote/quote_thanks.html" );
}
// Original file_upload.php code follows below
if (isset($_POST['submit'])) {
// Configuration - Script Options
$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension
$file_basename = substr($filename, 0, strripos($filename, '.')); // Get file name minus extension
$file_ext = substr($filename, strripos($filename, '.')); // Get file extension
$filesize = $_FILES['file']['size']; // Get file size
$allowed_file_types = array('.jpg','.jpeg','.gif','.bmp','.png','.pdf','.doc','.docx','.psd'); // These will be the types of files that are allowed to pass the upload validation
$file_counter = 1; // used to increment filename if name already exists
$company = $_REQUEST['company'];
$project = $_REQUEST['proj_name'];
// File renaming and upload functionality
if (in_array($file_ext,$allowed_file_types) && ($filesize < 10000001)) { // Checks to make sure uploaded file(s) is an allowed file type AND within the allowable file size (currently 10MB)
// Rename File
$newfilename = $company . '_' . $proj_name . '_' . $file_basename; // Rename file as (CompanyName_FileName_DateStamp)
// Loop until an available file name is found
while (file_exists( "file_uploads/" . $newfilename ))
$finalfilename = $newfilename . '_' . $file_counter++ . $file_ext; // This will be the File Name shown in the upload destination directory (currently the "file_uploads" directory)
if (file_exists("file_uploads/" . $finalfilename)) {
// file already exists error
echo "This file already exists. Please rename this file and upload again if necessary.";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "file_uploads/" . $finalfilename);
echo "File uploaded successfully.";
}
} elseif (empty($file_basename)) {
// file selection error
echo "Please select a file to upload.";
} elseif ($filesize > 10000000) {
//file size error
echo "The file you are trying to upload is too large. Files must be no larger than 10MB.";
} else {
// file type error
echo "The file you attempted to upload is not allowed. You can only upload the following types of files: .jpg, .jpeg, .gif, .bmp, .png, .pdf, .doc, .docx, and .psd.";
unlink($_FILES["file"]["tmp_name"]);
}
}
/*
must add page links for error and success messages:
// redirect to upload success url
header( "Location: http://www.example.com/thankyou.html" );
die();
*/
?>
On the live simplified form, I have disabled the quote_content_error check so that I did not have to recreate then entire form.
Any ideas as to why this php form does not work as intended? Did I combine the individual forms’ code int a single file incorrectly?