开发者

Readfile issue PHP

开发者 https://www.devze.com 2023-01-18 16:17 出处:网络
I\'m using the following : @header(\"Cache-Control: no-cache, must-revalidate\"); @header(\"Content-Type: application/octet-stream\");

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/downl开发者_JAVA百科oads/the file some spaces.mp3) [function.readfile]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/belgin/public_html/dl.php on line 29

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 :

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


I think your going to need to urlencode() and html_entities() the url or filename or whatever


It seems that the url contains spaces. Do you escape it properly for use inside readfile()?


DO NOT encode url! It will encode like http%3A%2F%2Fexample.com%2Fsome%20song.mp3. You just need to replace spaces. so use str_replace instead...

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


urlencode() is not the way to go. As mentioned above, simply use 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.

PHP has a setting called open_basedir

Make sure this is set correctly relevant to your hosting environment. open_basedir can be edited via php.ini

0

上一篇:

:下一篇

精彩评论

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