# Force download

**URL:** <https://forum.kirupa.com/t/force-download/99168>\
**Category:** Uncategorized\
**Created:** [January 15, 2004, 12:24pm UTC](https://forum.kirupa.com/t/force-download/99168 "2004-01-15T12:24:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pastawoua](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@pastawoua](https://forum.kirupa.com/u/pastawoua)\
**Post date:** [January 15, 2004, 12:24pm UTC](https://forum.kirupa.com/t/force-download/99168/1 "2004-01-15T12:24:29Z")

</div>

I ve tried the code taken from this older post :[http://www.kirupaforum.com/forums/showthread.php?threadid=34856](http://www.kirupaforum.com/forums/showthread.php?threadid=34856)

```php

<?php 
$filename = $_GET['filename']; 
if (ereg(".mp3$", $filename)) { 
header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/force-download"); 
header("Content-Type: application/octet-stream"); 
header("Content-Type: application/download"); 
header("Content-Disposition: attachment; filename=".basename($filename).";"); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($filename)); 
readfile("$filename"); 
} 
?> 

```

If my file is called “[http://www.mydomain.com/my](http://www.mydomain.com/my) music.mp3” this script doesnt work.  
Seems that spacing and distant file are not friend ☹

Local file + spaces = ok  
distant file + nospace = ok

distant file + spaces = not ok

When i m calling the script, it makes me download a “my music.mp3” file (5ko) with this error message in it:

> 

\<br /\>  
\<b\>Warning\</b\>: stat failed for [http://www.mydomain.com/my](http://www.mydomain.com/my) music.mp3 (errno=2 - No such file or directory) in \<b\>d:\easyphp\www\download.php\</b\> on line \<b\>12\</b\>\<br /\>  
\<br /\>  
\<b\>Warning\</b\>: Cannot add header information - headers already sent by (output started at d:\easyphp\www\download.php:12) in \<b\>d:\easyphp\www\download.php\</b\> on line \<b\>12\</b\>\<br /\>  
\<br /\>  
\<b\>Warning\</b\>: readfile(“[http://www.mydomain.com/my](http://www.mydomain.com/my) music.mp3”) - No such file or directory in \<b\>d:\easyphp\www\download.php\</b\> on line \<b\>13\</b\>\<br /\>

i’m going nuts ☹ if someone has an idea it would be great, thanks.
