PHP文件在浏览器中保存XML,但不作为计划的.bat文件保存
我有一个PHP文件,在浏览器中运行时,它成功地保存了大量XML文件,如下所示:PHP文件在浏览器中保存XML,但不作为计划的.bat文件保存,php,xml,batch-file,Php,Xml,Batch File,我有一个PHP文件,在浏览器中运行时,它成功地保存了大量XML文件,如下所示: $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-&
$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);
@ECHO OFF
php.exe -f "C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\sites\processDownloads.php"
我希望通过Windows任务调度器来安排执行此PHP文件,因此需要设置一个简单的.bat文件,如下所示:
$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);
@ECHO OFF
php.exe -f "C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\sites\processDownloads.php"
当通过任务计划执行此操作时,不会生成.xml文件-我在应用程序日志中看到此错误:
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
第442行是保存XML的行:
$dom->save($fileName);
我已将任务计划设置为以管理员身份运行,并选择了“以最高权限运行”。我看不到任何权限问题,特别是考虑到它在浏览器中工作,并且计划设置为以管理员身份运行。设置“开始(可选)”值到与我调用的.php文件相同的位置,为我修复了此问题。您可能需要从批处理脚本更改工作目录,因为您的保存路径是相对的。如果可能的话,也可以使用绝对路径。谢谢-我必须将Start In目录设置为存储php文件的同一个目录,并且在这之后一切都正常工作。