Предупреждение PHP в Filemtime () & Не удается изменить информацию заголовка - ошибка заголовков уже отправлена - PullRequest
0 голосов
/ 04 апреля 2011

С помощью @James генератор изображений находится в хорошем состоянии.Теперь есть небольшая, но странная ошибка, которую механизм изображений выводит, когда файл или папка не существует .На самом деле должна быть ошибка , но я не уверен, что это может быть ниже.Вот что происходит, когда Google пытается извлечь старую несуществующую папку / image.jpg с помощью генератора миниатюр imgcpu.php:

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

Вопрос: ошибка верна? или предупреждение следует как-то решить?Если так, то как?

1 Ответ

2 голосов
/ 04 апреля 2011

Вы не должны пытаться получить дату последнего изменения файла, если этот файл не существует, я полагаю.

Вы должны проверить, существует ли файл, сначала используя 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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...