简体   繁体   English

Readfile问题PHP

[英]Readfile issue PHP

I'm using the following : 我正在使用以下内容:

@header("Cache-Control: no-cache, must-revalidate");
@header("Content-Type: application/octet-stream");
@header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
@header("Content-Length: ".$row['file_size']);
@header("Content-Disposition: attachment; filename=\"".$row['artist'] . " - " .$row['title']."\"");
@header("Content-type: audio/mpeg;\r\n");

to start a download, now for some reason its giving me 开始下载,现在由于某种原因它给了我

Warning : readfile(http://theurl.com/downloads/the file some spaces.mp3) [function.readfile]: failed to open stream: HTTP request failed! 警告 :readfile(http://theurl.com/downloads/该文件一些spaces.mp3)[function.readfile]:无法打开流:HTTP请求失败! HTTP/1.1 404 Not Found in /home/belgin/public_html/dl.php on line 29 在第29行的/home/belgin/public_html/dl.php中找不到HTTP / 1.1 404

now the url is valid, I've triple checked but could it be because there's spaces in the file name? 现在该网址是有效的,我已经三重检查过,但这可能是因为文件名中有空格吗? And if so how can i fix that? 如果可以的话,我该如何解决? Thanks 谢谢

reafile line : reafile行:

readfile(http://domain.com/downloads/Warp 1.9_The Bloody Beetroots_320000.mp3)

我认为您将需要urlencode()和html_entities()的网址或文件名或其他内容

It seems that the url contains spaces. 网址似乎包含空格。 Do you escape it properly for use inside readfile()? 您是否将其正确转义以在readfile()中使用?

DO NOT encode url! 不要编码网址! It will encode like http%3A%2F%2Fexample.com%2Fsome%20song.mp3 . 它将像http%3A%2F%2Fexample.com%2Fsome%20song.mp3 You just need to replace spaces. 您只需要替换空格。 so use str_replace instead... 因此请改用str_replace ...

readfile(str_replace(" ", "%20", $url));

urlencode() is not the way to go. urlencode()不是要走的路。 As mentioned above, simply use str_replace(). 如上所述,只需使用str_replace()。

Just another possibility here as to why its not working. 关于为什么它不起作用的另一种可能性。 This was the cause for me. 这就是我的原因。 Interestingly, file_exists was returning true but no form of serving the file to the public for download was working without having the below set correctly. 有趣的是,file_exists返回的是true,但是如果未正确设置以下内容,则无法以任何形式将文件提供给公众下载。

PHP has a setting called open_basedir PHP有一个名为open_basedir的设置

Make sure this is set correctly relevant to your hosting environment. 确保此设置与您的托管环境正确相关。 open_basedir can be edited via php.ini 可以通过php.ini编辑open_basedir

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

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