1

I want to change directory using chdir in php, because i need to execute command in Linux. My current directory is /var/www/httpdocs/website/admin,I want to go to httpdocs's sub_directory docs.I use absolute path like:

chdir("/var/www/httpdocs/docs");

but it does't work.

I only can get website using : chdir("../"); or get admin's sub_directory images using : chdir("/var/www/httpdocs/website/admin/images");

but I can't get httpdocs. what's wrong?

Any tips would be appreciated.

Joke_Sense10
  • 5,341
  • 2
  • 18
  • 22
Kara
  • 11
  • 1
  • 2

1 Answers1

1

Are you sure you have enough user rights to go outside of the website directory ?

If you enable error display, maybe you will understand what's going on. Please try your script again by adding this on top of your php file:

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

And let me know which error messages you see.

Scalpweb
  • 1,971
  • 1
  • 12
  • 14
  • This should have been a comment instead. – Amal Murali Oct 15 '13 at 07:20
  • I did as what you said.But no error to give back.will it give errors when chdir() return false? – Kara Oct 15 '13 at 08:56
  • 1
    If you do `print_r(chdir("/var/www/httpdocs/docs"));` what can you see ? – Scalpweb Oct 15 '13 at 09:07
  • I try it and see nothing on web page.If I do if(chdir("/var/www/httpdocs/docs")) echo "a";else echo "b";Then I can see b on web page. – Kara Oct 16 '13 at 00:51
  • Are you sure that he path `/var/www/httpdocs/docs` is correct ? If it is, the only reason for this chdir to fail is due to a access forbidden. It can be due to a php safe_mode or your server configuration. Maybe try to change the chmod on the docs directory. – Scalpweb Oct 16 '13 at 07:10
  • Thank you very much.You are right.It really because of access forbidden. – Kara Nov 20 '13 at 02:09