php check if image exists on remote server

Solutions on MaxInterview for php check if image exists on remote server by the best coders in the world

showing results for - "php check if image exists on remote server"
Sarah
14 May 2019
1function remote_file_exists($url)
2{
3    $ch = curl_init($url);
4    curl_setopt($ch, CURLOPT_NOBODY, true);
5    curl_exec($ch);
6    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
7    curl_close($ch);
8    if( $httpCode == 200 ){return true;}
9}
10
11//THE USE THE BELOW FUNCTION CALL
12
13if(remote_file_exists($url))
14{
15    //file exists, do something
16}