views:

47

answers:

2

Hey,

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! 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)
+1  A: 

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

Vasileios Lourdas
how do i do that
Belgin Fish
+2  A: 

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

Ascherer
i hope its something like readfile($filename), if it is, change it to thisreadfile(html_entities(urlencode($filename)));
Ascherer
It should be `readfile(urlencode($filename));`, no `htmlentities()`, which is only needed to escape strings that are to be used in (X)HTML (in tags, attributes or for display).
Archimedix
now i'm getting readfile(http://domain.com/downloads%2FWarp+1.9_The+Bloody+Beetroots_320000.mp3) which isn't working (invalid url and everyhting)
Belgin Fish
ok, so you'll have to separaate the filename and the urlreadfile("domain.com/downloads/".html_entities(urlencode($filename)))
Ascherer
alright sec ill check it out
Belgin Fish
Hm... my mistake I guess. `urlencode()` also encodes the `http://` part of the URL which includes `:` and `/`. You should only be encoding the file name part. But again, no `htmlentities()`.
Archimedix
the htmlentities wont hurt anything, infact it makes the urls look better. + instead of %20
Ascherer
Archimedix
well, im mistaken then lol. Ive seen people doing the same thing i did, and thats what ive used, and its always worked for me, but if you dont need it, dont use it
Ascherer