I am trying to use the is_file() function to check if an image exists. Here is what I do :
<?php if(is_file("/images/tours/crop/$image")){ ?>
<img src="/images/tours/crop/<?php echo $image ?>">
<?php }
else {echo "Original image has not been cropped yet";} ?>
The image exists. When I just output the image, it appears. However, the function always returns false (and I'm getting the error). I thought it was a Windows problem, but when putting it on our demo server under Linux, the problem is still here.
Any help appreciated. Thanks
is_file()
is taking an absolute path as on the machine's filesystem. Unless you have /images
at the root of your filesystem, it's not going to work.
What you most likely want is something similar to
is_file("/var/www/html/application/images/tours/crop/$image")
(that would be whatever your application's path is, which can be determined with __DIR__
or dirname(__FILE__)
).
Use the complete path to the file with __DIR__
or dirname(__FILE__)
For example:
is_file(__DIR__.'/path/to_your_file.jpg');