Check if an file exists on the remote server

// Check if an file exists on the remote server
// CURLOPT_NOBODY: don't download content
$url = 'http://www.domain.com/file.jpg';
$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);
if (curl_exec($ch) !== FALSE) {
  // Remote file exist
}
curl_close($ch) ;

Leave a Reply