나는 내 워드 프레스 사이트 중 하나에 대해 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');
?>
http://php.net/manual/en/features.file-upload.post-method.php –
https : //developer.wordpress. org/reference/functions/wp_mail/# comment-345 –