SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem downloading mp3 files using PHP

    I've written PHP scripts to upload and download files from a website. I use move_uploaded_file to upload files, and readfile (after setting HTTP headers) to download files. I specify a MIME type of "application/audio/mpeg" for mp3 files in the download script.

    In the "Opening" window that appears when I run the download (giving me options to Open or Save on my computer) the file shows as "application/audio/mpeg", which is the MIME I'm setting in the download script. If I Save the file, it downloads fine but it won't open - it appears with a File Type of "File" in Windows Explorer. If I Open the file from the "Opening" window (instead of Save) using WMP11, it says "The selected file has an extension (.) that is not recognized by Windows Media Player". If I click "Yes", the file plays fine.

    Prior to any uploads or downloads, I'm able to play this mp3 file on my computer using WMP11 without a problem (appears as File Type "MP3 Format Sound). After I upload it with my upload script, it appears on the server with the same File Type, so seemingly, it's okay at that point.

    Any ideas are sincerely appreciated!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    "application/audio/mpeg" is not a standard mime type, I think you meant to use "audio/mpeg".

    As for the file name stuff, are you sending the right header to set a filename? It seems like you're not sending one at all so the browser doesn't know what to call the file.

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After I posted my problem, for some reason I thought about trying the download in another browser (I had only tried it with Firefox). The download works in IE7, Google Chrome, Safari, and Opera. So, I'm thinking it must be browser-related. I'm searching Firefox as we speak to try and find a fix.

  4. #4
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan - thanks for your reply.

    Here are the HTTP headers I'm sending:

    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=$filename");
    header("Content-Type: $ctype");
    header("Content-Transfer-Encoding: binary");

    I assign a value of "application/audio/mpeg" to $ctype and the value of $_REQUEST['downloadfile'] to $filename. I'm able to download files of many other types (.txt, .doc, .jpg. .png, ect) without a problem.

    I displayed the value of $filename during script execution and it looks just fine, (e.g., musicfileone.mp3).

    I have Amazon MP3 Downloader installed, and I've done a few searches to see if that is somehow interfering, but haven't found anything yet.

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It may or may not be the cause of your problem, but "application/audio/mpeg" is definitely wrong. If you search for that, the only results are this thread and copies of this thread.

  6. #6
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are right Dan - when I changed the MIME type (removed "application/") the downloads work fine.

    I checked the MIME list at w3schools and realized I had coded all of my "image" MIME's incorrectly. By the way, any idea why "png" is not listed there?

    Thank you so much for your help!

    David


Bookmarks

Posting Permissions

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