无法使用fopen()打开远程XML文件.我需要在服务器中设置什么所有权限,或者我需要在fopen()函数中设置什么参数? [英] Unable to open remote XML file using fopen(). What all permission i need to set in server or what parameters i need to set in fopen() function.?

查看:101
本文介绍了无法使用fopen()打开远程XML文件.我需要在服务器中设置什么所有权限,或者我需要在fopen()函数中设置什么参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过fopen()函数在远程服务器中打开XML文件. 我有两个远程服务器,并且两个服务器中xml的文件许可权都设置为777. 我能够从一台服务器打开xml,但不能从另一台服务器打开.这两个文件都可以在浏览器中打开.

I am trying to open an XML file in remote server through fopen() function. I have two remote servers and the file permission of the xml is set to 777 in both servers. i am able to open the xml from one server , but not from other. Both files can be opened in browser.

我需要在fopen()函数中设置所有权限还是需要设置哪些参数??

What all permission i need to set or what parameters i need to set in fopen() function.?

这是功能

function getFileData($ProjectName)
{
    $file = fopen($ProjectName, "r") or exit("Unable to open File! ".$ProjectName);
    $fileContent="";
        while(!feof($file))
          {
         $fileContent.=fgets($file);
          }
    fclose($file);
    echo $fileContent;
}

getFileData('http://serverA.com/myxml.xml'); // gives the content
getFileData('http://serverB.com/myxml.xml'); // gives the error fopen(http:/serverB.com/myxml.xml) [function.fopen]: failed to open stream: HTTP request failed!

推荐答案

在最后两行中,http:之后只有一个/-但我怀疑这是问题所在.可以在浏览器中打开文件吗?

You only have one / after http: in the last two lines - but I doubt that's the problem. Can you open the file in the browser?

也许尝试使用 file_get_contents .它的功能与您的功能相同,不同之处在于它已经由PHP专家准备并经过全面测试.

Perhaps try using file_get_contents . It does the same as your function, except it's ready made and fully tested by the PHP guys.

这篇关于无法使用fopen()打开远程XML文件.我需要在服务器中设置什么所有权限,或者我需要在fopen()函数中设置什么参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆