我试图从远程服务器下载图像,调整大小,然后保存本地机器。下载前检查图像是否存在于远程服务器
要做到这一点我使用WideImage。
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'libraries/wideimage/index.php');
include_once($_SERVER['DOCUMENT_ROOT'].'query.php');
do {
wideImage::load($row_getImages['remote'])->resize(360, 206, 'outside')->saveToFile($_SERVER['DOCUMENT_ROOT'].$row_getImages['local']);}
while ($row_getImages = mysql_fetch_assoc($getImages));
?>
这在大部分时间都有效。但它有一个致命的缺陷。
如果由于某种原因,这些图像中的一个不可用或不存在。 Wideimage引发致命错误。防止可能存在的下载图像。
我已经试过检查文件是否存在这样的
do {
if(file_exists($row_getImages['remote'])){
wideImage::load($row_getImages['remote'])->resize(360, 206, 'outside')->saveToFile($_SERVER['DOCUMENT_ROOT'].$row_getImages['local']);}
}
while ($row_getImages = mysql_fetch_assoc($getImages));
但是,这是行不通的。
我在做什么错?
感谢
为什么'file_exists()'检查工作,'$ row_getImages'如何定义? – 2011-05-06 14:56:30
$ row_getImages在包含的query.php中定义。 file_exists()似乎不起作用。 – jamjam 2011-05-06 15:00:39
不知道发生了什么回答,提到“尝试”和“赶上”,但它的工作。感谢大家。 – jamjam 2011-05-06 15:11:11