我试图检查我的图像是否存在于远程服务器中。我有大量图片(数百)。检查图像是否存在于远程服务器问题
我试过curl
和file_get_contents
函数,它们都会冻结我的浏览器,因为它需要很长时间来检查。
我的结构是这样的
<?php
for loops{
$ch = curl_init($imageFile[$i]);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if(retcode==200){
$imagePath = $imageFile[i]
}else{
$imagePth = 'badImage.gif';
}
curl_close($ch);
?>
//show images in table
<tr>
<td> <img src='".$imagePath."'/> </td> //show the image if the images exist.
</tr>
<?php
}
?>
我的代码将最终显示的图像,但它需要一个很长的时间。有没有减少时间或其他方式来做到这一点?非常感谢!
存在图像中有你的PHP尝试file_exists功能? – dee 2013-05-07 17:10:31
您可以通过使用AJAX轮询脚本以获取图像来进行渐进式加载。我假设现在的问题是,该页面正在永久加载,因为你的PHP脚本是从字面上下载每一个图像文件。 – thatidiotguy 2013-05-07 17:10:41
@webgal是的。加载时间相同。对于thatidiotguy你是什么意思,通过使用Ajax拉脚本? – Rouge 2013-05-07 17:16:33