0

I've got a PHP file that when run in the browser saves a number of XML files successfully as follows:

$fileName = 'savedFiles/'.$invoiceNumber.'xml';

// Save XML
$xml->asXML();

//Format XML to save indented tree rather than one line
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());

$dom->save($fileName);

I'd like to schedule this PHP file to be performed via the Windows Task Scheduler, so have setup a simple .bat file as follows:

@ECHO OFF
php.exe -f "C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\sites\processDownloads.php"

When this is executed via the Task Scheduled no .xml files are generated - I'm getting this error in the Application Log:

PHP Warning:  DOMDocument::save(xml_files/Invoice123.xml): failed to open stream: No such file or directory in C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\sites\processDownloads.php on line 442

Line 442 is the line that saves the XML:

$dom->save($fileName);

I've set the task schedule to run as Admin and "Run with highest privileges" is selected. I can't see any permissions issues, especially given it works in the browser and the schedule is set to run as Administrator.

user982124
  • 4,416
  • 16
  • 65
  • 140
  • 1
    You probably need to change the working directory from the batch script because your save path is relative. Or use an absolute path if possible. – Michael Berkowski Apr 18 '17 at 15:27
  • Thanks - I had to set the Start In directory to the same directory where the php file was stored and it all worked after that. – user982124 Apr 18 '17 at 22:55

1 Answers1

-1

Setting the "Start in (optional)" value to the same location as the .php file I was calling fixed this for me.

user982124
  • 4,416
  • 16
  • 65
  • 140