This spits out a whole heap of NO's but the images are there and path correct as they are displayed by <img>
.
foreach ($imageNames as $imageName)
{
$image = 'http://path/' . $imageName . '.jpg';
if (file_exists($image)) {
echo 'YES';
} else {
echo 'NO';
}
echo '<img src="' . $image . '">';
}
file_exists
uses local path, not a URL.
A solution would be this:
$url=getimagesize(your_url);
if(!is_array($url))
{
// The image doesn't exist
}
else
{
// The image exists
}
See this for more information.
Also, looking for the response headers (using the get_headers
function) would be a better alternative. Just check if the response is 404:
if(@get_headers($your_url)[0] == 'HTTP/1.1 404 Not Found')
{
// The image doesn't exist
}
else
{
// The image exists
}
file_exists looks for a local path, not an "http://" URL
use:
$file = 'http://www.domain.com/somefile.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
}
else {
$exists = true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With