I have been instructed to write some PHP scripts and a BAT file to invoke them. I was told that this BAT file is going to be invoked, in turn, by a master BAT file. This got me worrying about all the [man]include[/man] and [man]require[/man] statements. When I include 'someFile.php', where is PHP going to be looking for that file?
Relative to the master BAT file?
Relative to my BAT file?
* Relative to the PHP file?

I wrote a BAT file to invoke two php scripts: one in the directory with the BAT file and one in a subdirectory. Both php scripts tried to include a file called 'include.php' that was sitting in the same directory as the php file. Interestingly, the code in each PHP was evaluated relative to the BAT file rather than the php file.

I have been unable to do another test where I use a Master.BAT file to invoke Test.BAT and dir/Test.BAT because the echo statements of the PHP scripts don't bubble up to the top level.

Can someone help me figure this out. The basic question is If a file, MASTER.BAT, invokes other BAT files which call php scripts, how are relative paths evaluated?

I have attached my last test in a zip file.

    I believe the PHP relatvie paths would be relative to the directory in which the bat file is running. Therefore, you might want to have the bat file cd to the PHP script directory before calling the first PHP script.

      NogDog wrote:

      I believe the PHP relatvie paths would be relative to the directory in which the bat file is running. Therefore, you might want to have the bat file cd to the PHP script directory before calling the first PHP script.

      Yes, but which BAT file? I have Master.BAT calling Test.BAT and dir/Test.BAT which, in turn, call my php files. If dir/Test.BAT calls dir/Test.php, what is the working directory for the code inside dir/Test.php?

      I tried to test precisely that but the Master.BAT file doesn't echo the output of the php files.

        I just saw a note on the [man]include[/man] manual page suggesting starting your PHP script with this command so that it is running in the directory where its file is:

        <?php chdir(dirname(__FILE__)); ?>
        

          Something like that had occurred to me but it's truly helpful to have it handed to me. Thanks Nog.

            Write a Reply...