0

I have image exist and I can see it in both folder and browser but file_exists return always false. I did try 3 different paths but always return false I did try with :

$backgroundImage =  '/var/www/html/hmhb/bramijpadv2/uploads/space_banner/thmbs/20220203/047c7c10-69d5-47a2-996b-d1e938e0c3df/image01.jpg';

return false

$backgroundImage =  'http://127.0.0.1/hmhb/bramijpadv2/uploads/space_banner/thmbs/20220203/047c7c10-69d5-47a2-996b-d1e938e0c3df/image01.jpg';

return false

$backgroundImage =  '/hmhb/bramijpadv2/uploads/space_banner/thmbs/20220203/047c7c10-69d5-47a2-996b-d1e938e0c3df/image01.jpg';

return false

I did change permission to 777 I was thinking it's the problem but getting same result false

protected function hasImage($backgroundImage)
    {
        if (file_exists($backgroundImage))
        {
            return 'Image exist';
        }
        else{
            return 'No Image exist';
        }
    }

enter image description here enter image description here enter image description here

im-learning
  • 117
  • 2
  • 10
  • 1
    Have you tried calling `clearstatcache();` right before `file_exists`? Might be a caching issue. – Kevin Y Feb 07 '22 at 03:27
  • @KevinY yes still not working – im-learning Feb 07 '22 at 03:29
  • Does the directory exist at that location? `echo is_dir('/var/www/html/hmhb/bramijpadv2/uploads/space_banner/thmbs/20220203/047c7c10-69d5-47a2-996b-d1e938e0c3df/') ? 'directory exists' : 'directory does not exist';` – Kevin Y Feb 07 '22 at 03:30
  • @KevinY string(15) "directory exist" – im-learning Feb 07 '22 at 03:36
  • Try renaming the file to `image001.jpg` (with an extra 0) then adjust the code to have an extra 0. See if it can find it then. – Kevin Y Feb 07 '22 at 03:39
  • @KevinY still the same I did add 2 other images a png one and another jpg but still same problem – im-learning Feb 07 '22 at 03:45
  • What about `chdir('/var/www/html/hmhb/bramijpadv2/uploads/space_banner/thmbs/20220203/047c7c10-69d5-47a2-996b-d1e938e0c3df/');print_r(glob('*.jpg'));` does it list it? – Kevin Y Feb 07 '22 at 03:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/241775/discussion-between-kevin-y-and-im-learning). – Kevin Y Feb 07 '22 at 03:47
  • 1
    Does this answer your question? [file\_exists() returns false, but the file DOES exist](https://stackoverflow.com/questions/6930150/file-exists-returns-false-but-the-file-does-exist) – Kevin Y Feb 07 '22 at 04:33

0 Answers0