1

The below code works (print "file found" ) find if I run it from command line

php a.php

But if I try to access it from browser http://localhost/a.php It prints "file not found".

Its really weird the same URL works fine on the different machine. I am clueless why it is not working.

I have already checked open_basedir it is already disabled and there is no entry in the httpd.conf

 if(file_exists("/mnt/disk1/a.jpg"))
{ 
  echo "file found";
}     else
{ 
  echo "file not found";    }   ?>
9
  • 1
    Have you checked the file permissions ? And does web have enough read access? Commented Jul 18, 2016 at 11:59
  • yes I have given 777 permission to the file Commented Jul 18, 2016 at 12:00
  • Are you try clearstatcache() ? Commented Jul 18, 2016 at 12:04
  • Possible duplicate of file_exists() returns false even if file exist (remote URL) Commented Jul 18, 2016 at 12:04
  • You need to work with headers if you want to check for a file existence. In general the function works only with local files. Commented Jul 18, 2016 at 12:06

1 Answer 1

2

The web server user account must have permission to read the file - this is a different user account than the one you use on console.

sudo chmod +rx /mnt/disk1/a.jpg

Apache also needs execute access on all folders to root.

sudo chmod +x /mnt/disk1
sudo chmod +x /mnt
Sign up to request clarification or add additional context in comments.

1 Comment

thanks jeff somehow the same user create folder wittout executable permission

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.