简体   繁体   English

在外部调用时,PHP无法打开本地文件

[英]PHP can't open local file when called externally

I'm using the WorldPay payment gateway on a website I'm working on. 我正在使用的网站上使用WorldPay付款网关。 It handles all the credit card authorisation, and then calls a PHP file on my server with information about the transaction. 它处理所有信用卡授权,然后在服务器上调用有关交易信息的PHP文件。 It grabs the output from my script and displays it in the WorldPay chrome. 它从我的脚本中获取输出,并将其显示在WorldPay chrome中。

I don't know the inner workings, but I imagine that they'd be using something similar to cURL to post the transaction details to my script and to then retrieve the output. 我不知道内部工作原理,但是我想他们会使用类似于cURL的东西将交易详细信息发布到我的脚本中,然后检索输出。

My script writes the necessary information into an XML file, sends an email and then thanks the customer for shopping with us. 我的脚本将必要的信息写入XML文件,发送电子邮件,然后感谢客户与我们一起购物。

My problem is that when I test my file by calling it directly (by turning off the security checks and visiting http://example.com/mysite/myscript.php in my browser), everything works as planned, however when I go through the payment system (so I assumed my script is being called via cURL), it fails on this line: 我的问题是,当我通过直接调用文件(通过关闭安全性检查并在浏览器中访问http://example.com/mysite/myscript.php )测试文件时,一切都按计划进行,但是当我通过付款系统(因此我假设我的脚本是通过cURL调用的),但在此行失败:

$xml = simplexml_load_file('./info.xml');

Any ideas?? 有任何想法吗??

Clarification: that line returns false , which breaks the following lines. 澄清:该行返回false ,它中断了以下几行。

This might be a stretch, but check one of php's number one confusions with relative path resolution. 这可能是一个麻烦,但是请检查php相对路径解析的第一困惑。

'./' 

is relative to wherever Entrypoint is, not the script, which is why I use 是相对于Entrypoint所在的位置(而不是脚本)的,这就是为什么我使用

dirname(__FILE__).'/' 

everywhere instead. 到处都是。

Check your HTTP error logs -- make sure they're turned on. 检查您的HTTP错误日志-确保已将其打开。

It could be something like a read file permission problem. 这可能类似于读取文件权限问题。

Are you sure the path to info.xml is correct? 您确定info.xml的路径正确吗? That gets me sometimes when I am including a file from a subdirectory. 当我包含子目录中的文件时,有时会令我感到困惑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM