contactform7 で複数の添付ファイルをリサイズして送付
contactform7で添付ファイルを複数設定(下記ソースでは5つ)してfunctions.php内でリサイズをして送りたいのですが、
ファイルをリサイズするところまではできて、リサイズしたファイルを1つだけ添付することはできたのですが
複数のファイルを添付する方法をどなたかご教授頂けますでしょうか
PHP
1add_action("wpcf7_before_send_mail", "wpcf7_do_something"); 2 3function wpcf7_do_something($WPCF7_ContactForm){ 4 5 6 $wpcf7 = WPCF7_ContactForm::get_current(); 7 $submission = WPCF7_Submission::get_instance(); 8 $formatdata = $submission->uploaded_files(); 9 10 $timeStamp = $submission->get_meta('timestamp'); 11 $time = date('_Ymd_Gi', $timeStamp); 12 13 $uploadBaseDir = $_SERVER['DOCUMENT_ROOT']; 14 $uploadDirBase = $uploadBaseDir."/test/".$time; 15 16 17 // ディレクトリの有無の確認 18 if(file_exists($uploadDirBase)){ 19 // 存在する 20 }else{ 21 // 存在しない場合は作成 22 mkdir($uploadDirBase, 0777); 23 } 24 25 26 // サムネイルのサイズ 27 $thumbW = 800; 28 $thumbH = 450; 29 30 // ********************************************* 31 // 画像1の処理 32 $file1 = $formatdata['file-test1']; 33 if(!empty($file1)){ 34 $file1_path = func_img_resize($uploadDirBase, $thumbW, $thumbH, $file1, 1); 35 } 36 // 画像2の処理 37 $file2 = $formatdata['file-test2']; 38 if(!empty($file2)){ 39 $file2_path = func_img_resize($uploadDirBase, $thumbW, $thumbH, $file2, 2); 40 } 41 42 // 画像3の処理 43 $file3 = $formatdata['file-test3']; 44 if($file3){ 45 $file3_path = func_img_resize($uploadDirBase, $thumbW, $thumbH, $file3, 3); 46 } 47 48 // 画像4の処理 49 $file4 = $formatdata['file-test4']; 50 if($file4){ 51 $file4_path = func_img_resize($uploadDirBase, $thumbW, $thumbH, $file4, 4); 52 } 53 54 // 画像5の処理 55 $file5 = $formatdata['file-test5']; 56 if($file5){ 57 $file5_path = func_img_resize($uploadDirBase, $thumbW, $thumbH, $file5, 5); 58 } 59 60 61 62 if ($submission) { 63 $data = $submission->get_posted_data(); 64 if (empty($data)) 65 return; 66 67 $mail = $wpcf7->prop('mail'); 68 69 //添付ファイル指定(ここで複数設定したいです。) 70 $mail['attachments'] = $file1_path; 71 72 73 $wpcf7->set_properties(array( 74 "mail" => $mail, 75 )); 76 77 return $wpcf7; 78 } 79} 80 81 82// 画像のリサイズ 83function func_img_resize($uploadDirBase, $thumbW, $thumbH, $file, $_id){ 84 85 // ファイル名を取得 86 $pathData = pathinfo($file); 87 $file_name = $pathData['basename']; 88 89 //アップロード先 90 $uploadDir = $uploadDirBase."/".$_id."_".$file_name; 91 $uploadDir_resize = $uploadDirBase."/".$_id."_resize_".$file_name; 92 93 // ファイルのコピー 94 copy($file, $uploadDir); 95 96 // 元の画像のサイズを取得 97 list($w, $h) = getimagesize($uploadDir); 98 99 // リサイズ後の土台の画像 100 $thumbnail = imagecreatetruecolor($thumbW, $thumbH); 101 102 // 元の画像を読み込む 103 $baseImage = imagecreatefromjpeg($uploadDir); 104 105 // 元の画像を縮小してコピーペースト 106 imagecopyresampled($thumbnail, $baseImage, 0, 0, 0, 0, $thumbW, $thumbH, $w, $h); 107 108 // 圧縮率60で保存 109 imagejpeg($thumbnail, $uploadDir_resize, 60); 110 111 return $uploadDir_resize; 112 113}
回答1件
あなたの回答
tips
プレビュー