forcing download dialog not working

I’ve had a php document on our website for years that always worked in the past… I’m not sure why it’s not working now or when it stopped working. It’s possible I’ve changed something without realizing it. Can you please help?

The idea is that while the user is viewing a page at “” they click on a button to download an mp3 file, the button will call a php file from the top folder ( and that php file will target the mp3 file stored at, and the end result is that the user will be forced to choose to save the file or open it with their prefered app.

The HTML is stored in the subfolder “/bonus” and has this line of code, so when they click on the button it will run the php file.

The download.php file is stored in the top folder and looks like this

<? if(ereg("/", $songname)) { header("Status: 403"); die("Thou shalt not hack"); } header ("Content-Type: application/download"); header ("Content-Disposition: attachment; filename=$songname"); header("Content-Length: " . filesize("downloads/$songname")); $fp = fopen("downloads/$songname", "r"); fpassthru($fp); ?>

and the target file (i.e. pvrenchymv-aphagia.mp3) is stored in the subfolder “/downloads”

When you click on the button, instead of a pop-up dialog asking if you want to open or save “pvrenchymv-aphagia.mp3” it gives me a pop-up dialog asking if I want to open or save “download.php”. I have saved and opened the resulting file, and it is empty ( 0kb ).

I’ve tried moving everything into one folder and making the necessary code changes, but that did not help.

The odd thing to be is that it used to work fine, with lots of targeted files, using the folder structure I am currently using. I don’t remember changing anything.

Thank you very much for your time.

  • since posting this, I decided to simplify the problem by putting everything in one folder and work from there. After putting everything in one folder and eliminating folder references from the codes, I received this…

Warning: filesize() [function.filesize]: stat failed for downloads/ in /home/pvrenchy/public_html/bonus/download.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at /home/pvrenchy/public_html/bonus/download.php:8) in /home/pvrenchy/public_html/bonus/download.php on line 8

Warning: fopen(downloads/) [function.fopen]: failed to open stream: No such file or directory in /home/pvrenchy/public_html/bonus/download.php on line 9

Warning: fpassthru(): supplied argument is not a valid stream resource in /home/pvrenchy/public_html/bonus/download.php on line 10

I’m still trying to figure out where the problem is, but I’m not having any luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service