开发者

file_get_contents() and stream_get_contents() fail to open stream

I'm trying to force a file to be downloaded by sending it special headers. In doing so, I have to redirect URL requests for P开发者_运维知识库DF documents through my download script.

I pass a query called $seg3, which is base64_encode()ed before sending, and then base64_decode()ed and urlencoded() when trying to request the file.

I've taken a look at using,

if (ini_get('allow_url_fopen') == '1')
{
   $data = file_get_contents(urlencode(base64_decode($seg3)));
}
else
{
   $fp = fopen(urlencode(base64_decode($seg3)), 'rb');
   $data = stream_get_contents($fp);
   fclose($fp);
}

But both file_get_contents() and stream_get_content() fail with:

fopen($URL): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

Yet when I dump the URL that is being sent, I can copy and paste it in my browser and open the file.

It only seems to occur when spaces are in the file, yet the error occurs whether I use urlencode() or not.


It may be that an url returns a 404 error, but still returns regular contents as well. So while the browser may display a regular page, this function will fail because of the result code.


I'm sure this has been fixed already, but if there are spaces urlencode($url) might solve your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜