Issue When Attempting to Force 'Save File' Prompt with PHP
I'm attempting to create a form button which allows users to simple click to download mp3 files from my website. So far I have successfully created a button which, when clicked, forces the browsers 'Save File' prompt. However, once the download begins, it fails after downloading around 0.5kb.
The code I'm using is as follows...
header('Content-disposition: attachment; filename=/Tracks/All_Eyes_On_You_Acoustic.mp3');
<form><input type="button" value="Download" onClick="window.location.href='DownloadPHP/All_Eyes_On_You_Acoustic.php'"></form>
My understanding of PHP is essentially null, and the above code is in fact the result of a number of google searches on the subject, so I am at a complete loss as to how to fix this issue, and I've been unable to find a solution thus far.
The reason for using individual files to change the header content disposition, rather than applying it to all files of that type, is because I also wish to include a link on the page which will open the file within the browser.
Appriciate any replies.
Hmm. You shouldn't provide a path in header command. Really all the filename flag in the header is just telling the browser what to name the file when downloaded.
Try changing from
header('Content-disposition: attachment; filename=/Tracks/All_Eyes_On_You_Acoustic.mp3');');
and see if that works
header('Content-disposition: attachment; filename="All_Eyes_On_You_Acoustic.mp3"');
I've change this but it hasn't resolved the issue unfortunately.
Try this too...
Make sure the path is correct, use echo and file_exist() to debug.
Last edited by MrCoder; 01-09-2012 at 06:20 PM.
Originally Posted by temp.user123
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)