How do I check if a URL exists (not 404) in PHP?
get_headers() returns an array with the headers sent by the server in response to a HTTP request.
$image_path = 'https://your-domain.com/assets/img/image.jpg';
$file_headers = @get_headers($image_path);
//Prints the response out in an array
//print_r($file_headers);
if($file_headers[0] == 'HTTP/1.1 404 Not Found'){
echo 'Failed because path does not exist.';
}else{
echo 'It works. Your good to go!';
}