1

I'm moving a site from one server to another. On the old server, my code calls is_readable("filename") and it works. On the new server, it does not work. The files are exactly the same and "filename" is in the same place relative to the calling page.

When I put in an absolute path instead, is_readable returns true as expected. Any suggestions about what the problem could be?

safe_mode is off and open_basedir is not set in my php.ini. I also modified the file permissions, it doesn't work even if I chmod 777 (but that shouldn't matter since it reads properly when using the absolute path).

MF86
  • 275
  • 1
  • 4
  • 8
  • Thanks for the answers. It seems that, on the new server, the current working directory is not set to be the same as the directory executing the script. I'm unsure of how to configure this so created another question: http://stackoverflow.com/questions/5254000/php-how-to-set-current-working-directory-to-be-same-as-directory-executing-the-s – MF86 Mar 10 '11 at 00:19

3 Answers3

0

The servers probably have different configurations causing the current working directory (CWD) not to be the one where the script is being read. Relative paths are always relative to the CWD, not the current executing script.

You can check the CWD by calling getcwd() or by using realpath() to resolve the relative path into an absolute one. If the value is incorrect, you will have to either configure the server properly, or set the CWD manually by doing the following:

chdir(dirname(__FILE__));
Andrew Moore
  • 93,497
  • 30
  • 163
  • 175
0

Try using realpath on you relative path to check if it points to the right file.

You could also use getcwd to check if you're in the correct directory.

Czechnology
  • 14,832
  • 10
  • 62
  • 88
0

Typically, if you pass a relative path to is_readable (or file_exists), it will return false unless the path happens to be relative to the current PHP direct -- View PHP chdir info

TNC
  • 5,388
  • 1
  • 26
  • 28