我用在這裏找到郵件閱讀器腳本文件時丟失的變量值:https://github.com/stuporglue/mailreader試圖複製使用mailReader.php
我想上傳到另一個文件夾後的文件(S)複製。 文件正確上傳到腳本所在的文件夾。 當我嘗試運行復制命令時,文件名變量是空的。
以下是我正在使用的代碼部分:最後三行是我添加的內容。
private function saveFile($filename,$contents,$mimeType = 'unknown'){
$filename = preg_replace('/[^a-zA-Z0-9_-]/','_',$filename);
$unlocked_and_unique = FALSE;
while(!$unlocked_and_unique){
// Find unique
$name = time() . "_" . $filename;
$name = substr_replace($name,".pdf",-4); // added 1-19-2016
while(file_exists($this->save_directory . $name)) {
$name = time() . "_" . $filename;
$name = substr_replace($name,".pdf",-4);
}
// Attempt to lock
$outfile = fopen($this->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);
if (copy($this->save_directory.$name, "/attachments/" . TRANS_ID . "/". $name)) {
unlink($this->save_directory.$name);
}
我收到電子郵件確認文件已上傳,然後是另一封帶有錯誤消息的電子郵件。
警告:複製(/attachments/W7652222-546/1453406138_residential-print_from_td.pdf):未能打開流:在/home/myhost/public_html/mailreader/mailReader.php沒有這樣的文件或目錄上線224
224是我添加的代碼的行號。
源文件名是由在/附件前失蹤......
任何人有什麼想法?
是什麼讓你認爲文件名變量是空的?錯誤消息只是說目標目錄不存在。 'copy'將創建目標文件,但不會創建'W7652222-546'。 – Barmar
該文件存在於源目錄中,並且目標文件夾確實存在:(/attachments/W7652222-546/1453465663_residential-nitro.pdf) – user2413654
我收到與修改後的代碼完全相同的錯誤。 – user2413654