내 fucntions.php 파일에서 양식을 작성하고 유효성을 검증하는 단축 코드가 있습니다. 양식을 제출하고 유효성을 검증하면 데이터가 SESSION 변수에 저장됩니다. SESSION 변수는 사용자 정의 PHP 템플리트 페이지로 정보를 전달하는 데 사용됩니다. 이 페이지는 wp_mail()을 사용하여 양식 데이터를 전자 메일로 보내 주셔서 감사합니다.wp_mail() - 첨부 파일로 양식에서 'file'입력 유형 보내기
제 문제는 양식에 이미지 업로드를위한 '파일'입력 유형이 있다는 것입니다. 나는 그것이 올바르게 검증되었지만 업로드 된 이미지를 전송 한 다음 wp_mail() 함수의 '$ attachments'로 이메일을 보내면 고민 중입니다.
또한 업로드 된 이미지를 임시로 저장해야한다는 것을 알고 있습니다. 폴더를 SESSION 변수에 저장하지 말고 그냥 이메일을 보내면 이미지를 삭제하면됩니다.
내 모든 질문은 매우 길기 때문에 여기에 짧고 달콤한 버전 :
functions.php (A 단축 코드 기능에서)
<?php
$file = "";
$fileErr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//file upload is required, make sure its not empty
if(empty($_FILES['pmFile'])){
$fileErr = "This is required!";
}
else{
$file = $_FILES['pmFile'];//I validate here, but lets just say its OK
}
//If the error message is empty, store data in SESSION variables, and
//uploaded file in temp folder + redirect to thank you page
if(empty($fileErr)){
//HOW DO I SAVE THE FILE TEMPORARILY FOR USE ON THE NEXT PAGE???
wp_redirect('../wp-content/themes/rest of the path/thankYouPage.php');
exit();
}else{ /*display errors*/}
}
//down here is where I wrote the code for the form. YES method=post, YES I
//included enctype="multipart/form-data, YES the file input name is in fact
//'pmFile'.
?>
thankYouPage.php
//initial page stuff
//start email setup
$to = '[email protected]';
$email_from = '[email protected]';
$email_subject = "New Price Match Request";
$email_body = "I display the html and data here";
//for attachments
//HOW DO I PULL THAT UPLOADED FILE FROM THE TEMP FOLDER AND SEND IT AS AN ATTACHMENT?
$attachments = (the file in temp folder);
//NOW HOW TO I DELETE IT FROM THE TEMP FOLDER
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n"; //$email is a SESSION variable pulled from before
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//set to html
add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));
//send
wp_mail($to, $email_subject, $email_body, $headers, $attachments);
// Reset content-type to avoid conflicts
remove_filter('wp_mail_content_type', 'wpdocs_set_html_mail_content_type');
나는 그것을 제거 코드를 많이 알고 있지만, 이메일은 세션 변수에 의해 전송되는 형태로 다른 정보를 모두 작동합니다. 정말이 업로드 된 파일을 전송하고 이메일로 보내는 방법을 알아야합니다. 감사!
좋은 대답, 짧고 달콤한. 사실 이걸 시도하는 중입니다, 손가락이 엇갈 렸습니다. –
당신의 답변은 작동합니다! "_File이 비어 있습니다. 더 많은 것을 업로드하십시오.이 오류는 php.ini에서 업로드가 비활성화되었거나 post_max_size가 php.ini._에서 upload_max_filesize보다 작은 것으로 정의 된 경우에도 발생할 수 있습니다. "php.ini 파일을 편집하고 폴더 사용 권한이 올바른지 확인하고 하드 드라이브 공간을 충분히 확보했습니다. 어디서나 솔루션을 찾을 수 없습니다. –