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.?

混江龙づ霸主 提交于 2019-12-12 02:44:22

问题


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.

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

this is the 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!

回答1:


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?

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.




回答2:


I think there should be http://server and not http:/server.




回答3:


Apart from the visible problem with URL, also check what is the value for allow_url_fopen set in your php.ini, if you can open file from one server but not from other server this may be correctly set for you, did you check about timeouts?



来源:https://stackoverflow.com/questions/6938254/unable-to-open-remote-xml-file-using-fopen-what-all-permission-i-need-to-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!