我正在使用此脚本(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
);
}
有什么帮助吗?