Php 使用http获取文件内容-无法打开流

Php 使用http获取文件内容-无法打开流,php,http,web,fopen,Php,Http,Web,Fopen,我尝试使用PHP中的file\u get\u contents()-函数从网站获取文本 $myVariable = file_get_contents('myUrl/json/file.json?jsonp=loadSomething); 不幸的是,我一直收到这个消息 "Warning: file_get_contents(myUrl/json/file.json?jsonp=loadSomething): failed to open stream: HTTP reques

我尝试使用PHP中的
file\u get\u contents()
-函数从网站获取文本

        $myVariable = file_get_contents('myUrl/json/file.json?jsonp=loadSomething);
不幸的是,我一直收到这个消息

"Warning:
file_get_contents(myUrl/json/file.json?jsonp=loadSomething): 
failed to open stream: HTTP request failed! 
HTTP/1.1 404 Not Found in *path of my .php- file* on line 10"
在php.ini中,allow_url_fopen设置为“On”。我还尝试了
urlencode()
。 如何使代码正常工作?

好的,可以访问远程文件。当
file\u get\u contents
失败时,您的朋友是:

函数文件\u get\u contents\u curl($url){
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$URL);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_USERAGENT,'Mozilla/4.0(兼容;MSIE 6.0;Windows NT 5.1;SV1;.NET CLR 1.0.3705;.NET CLR 1.1.4322');
$data=curl\u exec($curl);
curl_close($curl);
返回$data;
}
现在试试

$myVariable = file_get_contents_curl('myUrl/json/file.json?jsonp=loadSomething');

你,即www用户,有权读取该目录?你是什么意思?代码在一个模块的“helper.php”文件中,安装在我的Joomla页面上,因此我相信www用户具有读取权限。我的意思是,您对
json/
有适当的用户权限吗?但是,如果您尚未使用绝对路径,请尝试使用绝对路径。我尝试打开的文件位于另一个网站上。我可以在浏览器中毫无问题地打开URL,它会向我显示一条纯文本消息。这是一条信息,我想保存在变量中。作为一个www用户,我确实可以访问“file.json”。谢谢你的回复。我现在没有收到任何警告或错误,但我仍然没有正确地收到网站的文本。调用该函数似乎只返回“0”。@msu welle-我开始相信您的远程站点会积极尝试防止刮擦等。。。请参阅更新,试图通过
CURLOPT\u USERAGENT
的浏览器假冒您的通话。