내 sendmail.php 및 fileupload.php 파일을 개별 기능으로 올바르게 사용할 수 있도록 도와 주신 모든 분들께 감사드립니다. 이제는 그들을 하나의 파일로 결합하려고합니다. 그래서 그것을 사용할 폼이 SUBMIT에서 두 함수를 수행 할 것입니다.두 개의 .php 파일을 하나의 단일 기능으로 결합하는 방법
<?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\n]", $name) || ereg("[\r\n]", $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("[email protected]", "Request for Quote: $project",
"$add_info\n
What kind of project is this? $project\n
Name: $name\n
Name of Project: $proj_name\n
Company: $company\n
Telephone: $phone\n
E-mail Address: $email\n
ZIP code: $zip\n
Is there a file attachment/upload? $upload\n
What do you need a quote on? $project : $project_other\n
What quantity do you require? $quantity\n
If applicable, how many pages is each document? $pages\n
Full color or black and white? $color : $color_other\n
What size do you want your print project to be? $size\n
What type of page layout do you need for your project? $page_layout\n
What paper stock do you require? $stock : $stock_other\n
What paper finish do you require? $paper_finish : $paper_finish_other\n
Are your documents typeset? $typeset\n
When do you need this project completed by? $timeframe\n
What is your budget for this project? $budget\n
Additional information to help COMPANY prepare our quote for you? $add_info",
"From: $name <$email>");
header("Location: ../pages/quote/quote_thanks.html");
}
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();
*/
?>
은 "센드 메일"부분이 작동하고 내가 명확하고 간결하게 나에게 이메일 내 폼 입력에 답변을 얻을 :
이 내가 현재 가지고있는 것입니다. 그러나, "file_upload"파일을 sendmail.php의 맨 아래에 추가 했으므로 (그냥 마지막으로 닫는 PHP 태그보다 위에 잘라서 붙여 넣으시겠습니까?>), file_upload와 이름 바꾸기 기능은 작동하지 않습니다.
이 파일을 단일 파일로 작업하는 방법에 대해 올바른 방향을 알려줄 수 있습니까? 나는 PHP에 새로운 것보다는 적다 그러나 어떤 생각/원조든지 평가 될 것입니다.
"작동하지 않음"을 정의하십시오. 어떤 오류가 발생합니까? – ceejayoz
죄송합니다. @ceejayoz. 나는 오류가 없다. 양식의 정보가 예상대로 포맷 된 이메일로 전송되지만 파일은 내 서버에 업로드되지 않습니다. 오류는 표시되지 않습니다. 그래서 그것은 파일 "작품"처럼 보이지만 기능의 file_upload 부분을 통해 따라하지 않습니다. 나는 PHP로 새로운 것보다 적기 때문에 어디에서 문제 해결을 시작할 지조차 알지 못한다. 파일 이름 변경 및 업로드 부분까지 도달하기 전에 함수가 중지 된 것 같습니다. – Craig