【发布时间】:2011-08-20 06:24:33
【问题描述】:
我正在尝试从远程服务器下载图像,调整大小,然后将其保存到本地计算机。
为此,我使用 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是如何定义的? -
$row_getImages 在包含的 query.php 中定义。 file_exists() 似乎根本不起作用。
-
不确定如何回答提到的“尝试”和“捕捉”,但它确实有效。谢谢大家。
-
您能否将您的 try and catch 解决方案添加到您的帖子中,以便其他人也可以从中受益?
标签: php file-get-contents file-exists