note 92451 deleted from function.getimagesize by cmb
| From: | cmb@php.net | Date: | Sun, 18 Dec 2016 09:40:09 +0000 |
| Subject: | note 92451 deleted from function.getimagesize by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208631@lists.php.net to get a copy of this message | ||
Note Submitter: mycrazydream
----
I had for quite some time been using getimagesize() to check for the existence of a remote image.
This turned out to take way too long. The following curl solution only checks the http headers so it
is much more efficient.
<?php
function checkRemoteFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE)
{
return true;
}
else
{
return false;
}
}
?>