このスクリプト(http://stuporglue.org/mailreader-php-parse-e-mail-and-save-attachments-php-version-2/)を使用して、電子メールの添付ファイルをサーバーに保存しています。こちらのブラウザで完全なスクリプトを表示することもできます:http ://stuporglue.org/downloads/mailReader.txt
すべて正常に動作しますが、ここには2つの問題があります。
1)ディレクトリに保存した画像のファイル名が画像ではありません:1360341823_test_jpg
How to convert the file name from 1360341823_test_jpg to 1360341823_test.jpg
in the script?
2)ディレクトリに保存されているファイルの権限は600です。
How to make it default 755 or 775?
これは、スクリプト内の画像を変換する関数だと思います。
function saveFile($filename,$contents,$mimeType){
global $save_directory,$saved_files,$debug;
$filename = preg_replace('/[^a-zA-Z0-9_-]/','_',$filename);
$unlocked_and_unique = FALSE;
while(!$unlocked_and_unique){
// Find unique
$name = time()."_".$filename;
while(file_exists($save_directory.$name)) {
$name = time()."_".$filename;
}
// Attempt to lock
$outfile = fopen($save_directory.$name,'w');
if(flock($outfile,LOCK_EX)){
$unlocked_and_unique = TRUE;
} else {
flock($outfile,LOCK_UN);
fclose($outfile);
}
}
fwrite($outfile,$contents);
fclose($outfile);
// This is for readability for the return e-mail and in the DB
$saved_files[$name] = Array(
'size' => formatBytes(filesize($save_directory.$name)),
'mime' => $mimeType
);
}
何か助けはありますか?