0

I am trying to import lot's of images into my database which is in my .csv file, but before importing i am trying to check if url of an image is valid or not by using 'getimagesize()' function in php.

When i use getimagesize() function to check url of an image is valid or not at that time my importing is working too slowly. So is there any other way to check image URL and import speedly as well please suggest me, Thanks in advance

shopeeon
  • 151
  • 2
  • 3
  • 14

1 Answers1

0

The fastest way to test a remote url is using CURL with the NOBODY flag enabled, if your server supports it.

function remoteFileExists( $url )
{
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL,$url );
    curl_setopt( $ch, CURLOPT_NOBODY, 1 );
    curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    $output = ( curl_exec( $ch ) !== false );
    curl_close( $ch ); 
    return $output; 
}
Rainner
  • 589
  • 3
  • 7