[Discuss] php question. change directory to executing script.

Eric Chadbourne sillystring at protonmail.com
Mon Dec 18 11:39:46 EST 2017


Hi All,

I have a little function that needs to delete some files.  I don't want it to delete them from the directory of my user, but in the directory of the script.

For example from terminal:

cd $HOME
php /path/to/script/foo.php  // will execute foo in home

But I want it to execute foo in /script.

So in the function I told it to change working directory to script path.

chdir(dirname(__FILE__));

Am I missing something or is this OK?  Is it evil to do such a thing?

Thanks,
Eric Chadbourne


More information about the Discuss mailing list