我有一个软件,每分钟上传一个jpeg到FTP帐户。
在PHP中,我在crontab中编写了一些PHP代码,这些代码接受最后的JPEG文件并执行图形处理。这个很好用。
$all_files = scandir("./dir/dir",1);
$last_files = $all_files[0]; //take last jpeg
..etc..问题是,有时crontab中的PHP代码接受一个仍在FTP上编写的文件(因此它是不完整的),并生成此错误:
[01-Jun-2016 15:30:05 Europe/Rome] PHP Warning: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file in /home/asdasd/public_html/www.asdasdasdasd.com/asd/asd/cron.php on line 15
[01-Jun-2016 15:30:05 Europe/Rome] PHP Warning: imagecreatefromjpeg(): './dir/dir/153000.jpg' is not a valid JPEG file in /home/asdasd/public_html/www.asdasdasdasd.com/asd/asd/cron.php on line 15
[01-Jun-2016 15:30:05 Europe/Rome] PHP Warning: imagecopyresampled() expects parameter 2 to be resource, boolean given in /home/asdasd/public_html/www.asdasdasdasd.com/asd/asd/cron.php on line 17我如何添加一个扫描检查,以捕获最后一个完整的文件而没有被写入?
发布于 2016-06-01 14:07:08
在处理该文件之前,只需检查它是否有效(cron.php):
if(exif_imagetype($filepath) != IMAGETYPE_JPEG){
// Exit the script
exit;
}
// Your image processing code goes here...http://php.net/manual/en/function.exif-imagetype.php
https://stackoverflow.com/questions/37570625
复制相似问题