0
我正在使用此腳本(http://stuporglue.org/mailreader-php-parse-e-mail-and-save-attachments-php-version-2/)將電子郵件附件保存到我的服務器上。您也可以在瀏覽器上查看完整腳本:http://stuporglue.org/downloads/mailReader.txt解析電子郵件並將附件保存到目錄中的問題
一切正常,但這裏有兩個問題。
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
);
}
任何他的功能的LP?
您可以考慮使用此Python腳本:https://github.com/auino/mail-附件存檔器 – auino 2016-10-04 06:22:15