0
私のサーバー上の特定の電子メールの添付ファイルをダウンロードするPHPスクリプトが正常に作成されました。php imap関数は破損したファイルをダウンロードします
ただし、それらはすべて壊れているようです。が
/* iterate through each attachment and save it */
foreach($attachments as $attachment){
if($attachment['is_attachment'] == 1)
{
$filename = $attachment['name'];
if(empty($filename)) $filename = $attachment['filename'];
if(empty($filename)) $filename = time() . ".dat";
/* prefix the email number to the filename in case two emails
* have the attachment with the same file name.
*/
$converted = utf8_decode(iconv_mime_decode($filename));
$text = preg_replace('/[^a-zA-Z0-9_.]/', '_', $converted);
$fp = fopen("att/".$text, "w+");
fwrite($fp, $attachment['attachment']);
fclose($fp);
}
}
機能を保存する前に、正規表現は、多くの場合に表示される特殊文字を変換します。私は、ダウンロードのために使用します(正しいファイル名は、ダウンロードしたが、サーバー上の0キロバイトのファイルサイズが)ここで
は私のコードです添付ファイル。
ここで改善することはできますか?次の行に問題があります
おかげで、あなたは何を意味するかわからないが、正確に...私は、これはファイル名... – mirzahat
は基本的にiconv_mime_decodeは、ファイルの内容を解読を台無しだと思います。あなたはファイル名を与えています。ファイルを読み込み、ファイル名ではなく内容を渡す必要があります。 – RCrowt
添付ファイルの内容は$ filename内ではなく、fwrite($ fp、$ attachment ['attachment'])行にあります。 ...この行は問題だと私は思います – mirzahat