簡體   English   中英

Filemtime中的PHP警告()&無法修改標頭信息 - 標頭已發送錯誤

[英]PHP Warning in Filemtime() & Cannot modify Header information - Headers Already Sent Error

在@James的幫助下,圖像生成器處於良好狀態。 現在,當文件或文件夾不存在時,圖像引擎會輸出一個微小而奇怪的錯誤。 確實應該有一個錯誤,但我不確定它是否應該是下面這個。 以下是谷歌嘗試通過imgcpu.php縮略圖生成器獲取舊的不存在的文件夾/ image.jpg時發生的情況:

[20:24:25] PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for old_folder/old-image.jpg in imgcpu.php on line 802
[20:24:25] PHP Warning: Cannot modify header information - headers already sent by (output started at imgcpu.php:802) in imgcpu.php on line 201

[20:26:31] PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for old_folder/old-image.jpg in imgcpu.php on line 802
[20:26:31] PHP Warning: Cannot modify header information - headers already sent by (output started at imgcpu.php:802) in imgcpu.php on line 201

[20:28:24] PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for old_folder/old-image.jpg in imgcpu.php on line 802
[20:28:24] PHP Warning: Cannot modify header information - headers already sent by (output started at imgcpu.php:802) in imgcpu.php on line 201

[20:31:03] PHP Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for old_folder/old-image.jpg in imgcpu.php on line 802
[20:31:03] PHP Warning: Cannot modify header information - headers already sent by (output started at imgcpu.php:802) in imgcpu.php on line 201 

201和802行似乎與它有關:

line 201**     header('HTTP/1.1 400 Bad Request');
line 202       die($message);
....
line 801       header("Content-type: " . $this->_mime);
line 802**     $last_modified = filemtime($source);

問題:錯誤是否正確? 或者警告應該以某種方式解決? 如果是這樣,怎么樣?

我想,如果該文件不存在,您不應該嘗試獲取文件的最后修改日期。

您應首先使用file_exists()函數檢查文件是否存在。


我想你應該使用這樣的東西:

if (file_exists($source)) {
    $last_modified = filemtime($source);
    // Use the $last_modified variable
}
else {
    // the file doesn't exist => 404
    header('HTTP/1.1 404 Not Found');
    die;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM