2017-01-26 13 views
0

나는 내 워드 프레스 사이트 중 하나에 대해 HTML 폼을 완성했다. 제출되면 WP_User 데이터베이스 테이블에 해당 사용자를 사용자로 만들고 양식의 모든 정보가 포함 된 전자 메일을 보냅니다. 그러나, 내 HTML 양식은 사용자가 필요한 파일을 업로드 할 수 있지만 전자 메일은 파일 이름 만 표시합니다. 나는 실제 파일을보고 다운로드 할 수있는 방법을 찾고 있습니다. 당신이 당신의 폼 태그에PHP로 html 폼에서 파일 업로드하기

에 enctype 속성 세트를 enctype="multipart/form-data"를 추가 할 필요가

<div id="container"> 
    <form method="post" name="myForm"> 
    <h1 align="center">Welcome!</h1> 
    <h2 align="center">Thank you for your interest. We look forward to working with you.</h2> 
    <h3>First Name</h3> <input type="text" name="fName" style="width: 355px;"/> 
    <h3>Last Name</h3> <input type="text" name="lName" style="width: 355px;"/> 
    <h3>Company Name</h3> <input type="text" name="compName" style="width: 355px;"/> 
    <h3>Business Needs</h3> 
    <select name="businessNeeds" style="width: 355px;"> 
    <option value="">Select...</option> 
    <option value="IntDesign">Interior Designer</option> 
    <option value="Ecom">E-Commerce Only</option> 
    <option value="Retail">Retail Store Only</option> 
    <option value="RetailEcom">Retail and E-Commerce</option> 
    <option value="Mult">Multiple Locations</option> 
    </select> 
    <h3>Address</h3> <input type="text" name="address" style="width: 355px;"/> 
    <h3>City</h3> <input type="text" name="city" style="width: 355px;"/> 
    <h3>State</h3> <input type="text" name="state" style="width: 355px;"/> 
    <h3>Zip</h3> <input type="text" name="zip" style="width: 355px;"/> 
    <h3>Phone</h3> <input type="text" name="phone" style="width: 355px;"/> 
    <h3>Email</h3> <input id="email" type="text" name="uemail" style="width: 355px;"/> 
    <h3>Create a Username</h3> <input type="text" name="uname" style="width: 355px;"/> 
    <h3>Create a Password</h3> <input type="password" name="pass" style="width: 355px;"/> 
    <h3>Confirm Password</h3> <input type="password" name="ConfPass" style="width: 355px;"/> 
    <h3>Sales Tax ID</h3> <input type="text" name="taxID" style="width: 355px;"/> 
    <h3>Upload Tax ID Certificate</h3> <input type="file" name="fileUpload" style="width: 355px;"/> 
    <input type="submit" value="Submit" /> 
</form> 
</div> 


<?php 
function create_account(){ 

$fName = (isset($_POST['fName']) ? $_POST['fName'] : ''); 
$lName = (isset($_POST['lName']) ? $_POST['lName'] : ''); 
$compName = (isset($_POST['compName']) ? $_POST['compName'] : ''); 
$businessNeeds = (isset($_POST['businessNeeds']) ? $_POST['businessNeeds'] : ''); 
$address = (isset($_POST['address']) ? $_POST['address'] : ''); 
$city = (isset($_POST['city']) ? $_POST['city'] : ''); 
$state = (isset($_POST['state']) ? $_POST['state'] : ''); 
$zip = (isset($_POST['zip']) ? $_POST['zip'] : ''); 
$phone = (isset($_POST['phone']) ? $_POST['phone'] : ''); 
$email = (isset($_POST['uemail']) ? $_POST['uemail'] : ''); 
$user = (isset($_POST['uname']) ? $_POST['uname'] : ''); 
$pass = (isset($_POST['upass']) ? $_POST['upass'] : ''); 
$ConfPass = (isset($_POST['ConfPass']) ? $_POST['ConfPass'] : ''); 
$taxID = (isset($_POST['taxID']) ? $_POST['taxID'] : ''); 
$fileUpload = (isset($_POST['fileUpload']) ? $_POST['fileUpload'] : ''); 

$email_from = 'admin'; 
$email_subject = "New Wholesale Form Submission"; 
$message = "You have received a new message from: \n"; 
$message .= "First Name: " .$_POST["fName"]. "\n";        
$message .= "Last Name: ".$_POST["lName"]. "\n"; 
$message .= "Company Name: ".$_POST["compName"]. "\n"; 
$message .= "Business Type: " .$_POST["businessNeeds"]. "\n"; 
$message .= "Address: ".$_POST["address"]. "\n"; 
$message .= "City: ".$_POST["city"]. "\n"; 
$message .= "State: ".$_POST["state"]. "\n"; 
$message .= "Zip: ".$_POST["zip"]. "\n"; 
$message .= "Phone: ".$_POST["phone"]. "\n"; 
$message .= "Email: ".$_POST["uemail"]. "\n"; 
$message .= "Tax ID: ".$_POST["taxID"]. "\n"; 
$message .= "Certificate: ".$_POST["fileUpload"]. "\n"; 


$to = "email"; 
$headers = "From: $email_from \r\n"; 



if (!username_exists($user) && !email_exists($email)) { 
    $user_id = wp_create_user($user, $pass, $email); 
    if(!is_wp_error($user_id)) { 
     //user has been created 
     $user = new WP_User($user_id); 
     $user->set_role('subscriber'); 


     wp_mail($to, $email_subject, $message, $headers); 


     //Redirect 
     wp_redirect('URL'); 
     exit; 
    } else { 
     //$user_id is a WP_Error object. Manage the error 
    } 
} 

} 
add_action('init','create_account'); 
?> 
+0

http://php.net/manual/en/features.file-upload.post-method.php –

+0

https : //developer.wordpress. org/reference/functions/wp_mail/# comment-345 –

답변

1

또는 형태에 enctype 속성의 값을 반환합니다 : 여기 내 코드는 지금까지입니다.

은 PHP 버전 속성은 폼 데이터가 서버로 전송하기 전에 인코딩되어야 하는지를 지정한다. 폼 데이터는 기본적으로 "애플리케이션/x-www-form-urlencoded를"로 부호화된다

. 즉, 모든 문자는 서버로 보내지기 전에 인코딩됩니다 (공백은 "+"기호로 변환되고 특수 문자는 ASCII 16 진수 값으로 변환됩니다).

(multipart/form-data) 문자는 인코딩되어 있지 않습니다. 이 값은 파일 업로드 컨트롤이있는 양식을 사용할 때 필요합니다.

+0

고마워요, 제 생각 엔 제대로 된 것 같아요. 나는 PHP 매뉴얼 사이트에 명시된 바와 같이 메소드 앞에 form 태그 안에 넣었고, 지금은 이메일을 받았을 때 파일 이름이 없어졌지만 비어있어 파일을 열거 나 다운로드 할 링크가 없다. 아무것도 PHP에 직접 추가해야합니까? –

+0

여기 https://www.tutorialspoint.com/php/php_file_uploading.htm – Divyank

+0

아 참조 메일 사용자 그런 다음 서버에 해당 파일의 링크 파일을 업로드해야합니다, 나는 그것을 직접 보낼 수 있다고 생각. 나는 그 대본에 대해 일할 것이다, 고마워! –

관련 문제