ロリポップで受信メールの添付ファイルをサーバーに保存したいのですが、
以下サイトのコードをお借りして試しており、保存までは出来るようになったのですが、
http://d.hatena.ne.jp/oniloq/20121129/1354122428
ファイルが壊れているようで開けません。
どのようにすればよろしいでしょうか?
// 添付を取得
if( !empty($attached_data) ) {
foreach( $attached_data as $key => $value) {
$attached=imap_fetchbody($mbox, $mailno, $key+1, FT_INTERNAL);
if(empty($attached)) break;
// ファイル名を一意の名前にする(同じファイルが存在しないように)
list($name, $ex)=explode('.', $value['file_name']);
$mail[$mailno]['attached_file'][$key]['file_name']=$name.''.time().''.$key.'.'.$ex;
$mail[$mailno]['attached_file'][$key]['image']=imap_base64($attached);
$mail[$mailno]['attached_file'][$key]['content_type']='Content-type: image/'.strtolower($value['content_type']);
// ★以下追加 $moto_file = $value['file_name']; $puus = dirname(__FILE__) . '/'; $savePath = $puus.$moto_file; if ($fp = fopen($savePath, "w")) { $length = strlen($body); fwrite($fp, $body, $length); fclose($fp); print '保存ファイル: '.$moto_file.'<br>'; } // ★追加ここまで }
}
的外れでしたらスミマセン。
どうか宜しくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2016/10/07 04:07