0

このスクリプト(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
  );
}    

何か助けはありますか?

4

1 に答える 1

1

元のスクリプトはデータを使用してDBに保存しましたが、ファイルに保存しようとしていると思います。ここで拡張子なしでファイルを作成しています:

 // Attempt to lock
    $outfile = fopen($save_directory.$name,'w');

次のように行の後に.jpgを追加します。

 #outfile.=".jpg";

他の方法では、スクリプトを変更したくない場合は、次のように使用できます。

 $contents = file_get_contents($save_directory.$name);
 $outfile = fopen($save_directory.$new_name,'w');
 write($outfile,$contents);
 fclose($outfile);

これで最初の問題が解決し、2番目の質問については、提供されているFTPまたはコントロールパネルを使用してファイルにアクセスし、所有権を変更してください。何もわからない場合は、Webホスティングサービスプロバイダーに連絡して、755から775までの所有権を共有してください。

于 2013-02-08T18:45:06.770 に答える