Results 1 to 4 of 4

Thread: Issue When Attempting to Force 'Save File' Prompt with PHP

  1. #1
    Join Date
    Jan 2012

    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');
    header('Content-type: audio/mpeg');
    <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.

  2. #2
    Join Date
    Aug 2008
    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');');

    header('Content-disposition: attachment; filename="All_Eyes_On_You_Acoustic.mp3"');
    and see if that works
    Free, Quick, SEO Friendly Backlinks: XEGS.com Web Directory

    Free Image Hosting

  3. #3
    Join Date
    Jan 2012
    Thanks ScottAN

    I've change this but it hasn't resolved the issue unfortunately.

  4. #4
    Join Date
    Jun 2006
    Down at the bottom of the garden
    Try this too...

    PHP Code:
    Make sure the path is correct, use echo and file_exist() to debug.
    Last edited by MrCoder; 01-09-2012 at 06:20 PM.
    Quote Originally Posted by temp.user123
    You know... You're not so smart. Do you need me to educate you?
    If you say, "please," (and do so, nicely) then I will show you where you're dead wrong.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center