【发布时间】:2015-11-20 20:24:51
【问题描述】:
我正在尝试用一串文本检查两件事。首先,我想检查它是否是真实的 URL。然后,如果是,我想检查该 URL 是否是图像。我遇到了this answer,它说要执行以下操作:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$imageURL);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE) {
print_r("went Throught");
}
else {
print_r("Failed");
}
curl_close($ch);
无论$imageURL 是什么,我总是得到Failed。我怎样才能实现以下目标:
if ($imageURL isRealUrl) {
// Do some code
if ($imageURL isInArrayOfImages(.png, .jpg, .GIF) {
// Do something
}
}
【问题讨论】:
-
好吧,您同时使用了 $imageURL 和 $url。是哪个?
-
为什么不用
getimagesize()的答案?