开发者

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

With help of @James, the image generator is in fine condition. Now, there is a tiny but strange error that the image engine outputs when a file or folder is non existent. Indeed there should be an error but i'm unsure wether it sould be this one below. Here is what happens when google tries to fetch an old non existent folder/image.jpg via the imgcpu.php thumbnail generator:

[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:开发者_如何学Python28: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 

It seems that line 201 and 802 have something to do with it:

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);

Question: Is the error correct? or should the warning be solved somehow? If so, how?


You should not try to get the last modification date of a file if that file doesn't exist, I suppose.

You should check whether the file exists, first, using the file_exists() function.


I suppose you should use something like this :

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜