これはコードのサンプルにすぎません。基本的に、アップロードする 4 つのファイルを含むフォームがあります。ファイルはサーバー上の指定されたフォルダーに正常に保存されます。しかし、それらが空であるため、明らかにそれらを適切に取り付けていません....誰か助けてもらえますか?
また、添付ファイルにはファイル名ではなくディレクトリ名が表示されます...何が欠けていますか?
どうもありがとう!!!
<?php
$username= protect($_POST['username']);
$firstName= protect($_POST['firstName']);
$lastName= protect($_POST['lastName']);
$email= protect($_POST['email']);
$program= protect($_POST['program']);
$dob= protect($_POST['dob']);
$transcript= $_FILES['transcript'];
$resume= $_FILES['resume'];
$letterIntent= protect($_POST['letterIntent']);
$reference1= $_FILES['reference1'];
$reference2= $_FILES['reference2'];
$relevantExperience= protect($_POST['relevantExperience']);
$volunteerExperience= protect($_POST['volunteerExperience']);
$reasonsAbroad= protect($_POST['reasonsAbroad']);
$definitionSuccess= protect($_POST['definitionSuccess']);
$futureGoals= protect($_POST['futureGoals']);
$challengeYourself= protect($_POST['challengeYourself']);
$challengeDevelopment= protect($_POST['challengeDevelopment']);
if (isset($_FILES) && (bool) $_FILES) {
$allowed_ext = array('doc', 'pdf', 'txt', '');
$files = array();
foreach($_FILES as $name=>$file) {
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_size = $file['size'];
$path_parts = pathinfo($file_name);
$file_ext = $path_parts['extension'];
if(!in_array($file_ext, $allowed_ext)) {
die ("extension for file $file_name not allowed");
}
if($file_size > 2097152) {
die ("File size must be under 2MB");
}
$server_file = "wp-content/uploads/application-documents";
move_uploaded_file($file_tmp, "$server_file/$file_name");
array_push($files, $server_file);
}
$to = ".....@gmail.com";
$from = "$email";
$subject ="Application from $firstName $lastName with attachments";
$msg = "hello";
$headers = "From: $from";
//define email boundaries
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
$message ="\n\n--{$mime_boundary}\n";
$message .="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .="Content-Transfer-Encoding: 7bit\n\n" . $msg . "\n\n";
$message .= "--{$mime_boundary}\n";
foreach($files as $file) {
$aFile = fopen($file,"rb");
$data = fread($aFile,filesize($file));
fclose($aFile);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: {\"application/octet-stream\"};\n";
$message .= " name=\"$file\"\n";
$message .= "Content-Disposition: attachment;\n";
$message .= " filename=\"$file\"\n";
$message .= "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n";
}
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>mail sent to $to</p>";
} else {
echo "<p>mail could not be sent!</p>";
}
}
}
?>