PHP Download bug with MP files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tader
    New Member
    • Sep 2007
    • 43

    PHP Download bug with MP files

    Here is my php download mp3 script

    Code:
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Type: audio/mpeg");
    header("Content-Disposition: attachment; filename = " . $file_name . ";");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . filesize($file));
    @readfile($file);
    and it opens my file ant it starts to download but it don't show how much time left hot to fix it?
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by tader
    Here is my php download mp3 script

    Code:
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Type: audio/mpeg");
    header("Content-Disposition: attachment; filename = " . $file_name . ";");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . filesize($file));
    @readfile($file);
    and it opens my file ant it starts to download but it don't show how much time left hot to fix it?
    I believe it is up to your web browser to determine the time left for a download, not any headers you set.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Yep I would have to go with Markus on this one.
      You are even sending the Content-Length header, so the browser should have all it needs to calculate this.

      Perhaps you need to upgrade your browser?
      Just out of curiosity, which browser are you using now?

      Comment

      • tader
        New Member
        • Sep 2007
        • 43

        #4
        im using Firefox 3.0.5

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by tader
          im using Firefox 3.0.5
          Same version I'm using and anything I download it gives me the remaining time left for it.

          Comment

          • tader
            New Member
            • Sep 2007
            • 43

            #6
            maybe it's because the file size is big try to open this i tryed this script on other computer is didn't work as well

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              Originally posted by tader
              maybe it's because the file size is big try to open this i tryed this script on other computer is didn't work as well
              Do you have a link?

              Comment

              • tader
                New Member
                • Sep 2007
                • 43

                #8
                http://www.mp3talpykla.com/_download.php try yourself but it will work like i said

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  I tried this, and it does indeed appear like the "Content-Length" header is not getting through. Both Firefox and Opera download the file as if they do not know it's size.

                  It's weird tho, because when I request the headers, the Content-Length header is getting sent:
                  Code:
                  HEAD /_download.php HTTP/1.1
                  Host: www.mp3talpykla.com
                  Connection: close
                  
                  HTTP/1.1 200 OK
                  Date: Wed, 28 Jan 2009 18:02:22 GMT
                  Server: Apache/2
                  X-Powered-By: PHP/5.2.6
                  Pragma: public
                  Expires: 0
                  Cache-Control: public
                  Content-Description: File Transfer
                  Content-Disposition: attachment; filename = Roland_Klinkenberg_-_Dusty_Horizon_(Max_Graham_club_mix_(www.mp3talpykla.com).mp3;
                  Content-Transfer-Encoding: binary
                  Content-Length: 8003580
                  Vary: Accept-Encoding,User-Agent
                  Connection: close
                  Content-Type: audio/mpeg
                  One thing that that might be off tho. You add a semi-colon after the filename. It shouldn't be there. Maybe that is causing some parse errors.

                  Comment

                  • tader
                    New Member
                    • Sep 2007
                    • 43

                    #10
                    i deleted it and it don't work!!!

                    Comment

                    • Atli
                      Recognized Expert Expert
                      • Nov 2006
                      • 5062

                      #11
                      Ok. I tested your code on my test server, and it works perfectly. I get the time remaining and everything.


                      This is the code I used:
                      [code=php]<?php
                      $file = "../hitakutur/Songs/Hitakutur - G-era.mp3";
                      $file_name = "Hitakutur - G-era.mp3";
                      header("Pragma: public");
                      header("Expires : 0");
                      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                      header("Cache-Control: public");
                      header("Content-Description: File Transfer");
                      header("Content-Type: audio/mpeg");
                      header("Content-Disposition: attachment; filename=\"" . $file_name . "\"");
                      header("Content-Transfer-Encoding: binary");
                      header("Content-Length: " . filesize($file) );
                      @readfile($file );
                      ?>[/code]
                      I only made minor alterations to the Content-Disposition line.
                      (Added the quotes around the name and removed the extra semi-colon)

                      So, if this code is in fact not working properly on your server, the server itself must be the problem, not the code.

                      Did you set the server up yourself?

                      Comment

                      • tader
                        New Member
                        • Sep 2007
                        • 43

                        #12
                        well your example didn't work :|

                        Comment

                        • Atli
                          Recognized Expert Expert
                          • Nov 2006
                          • 5062

                          #13
                          Originally posted by tader
                          well your example didn't work :|
                          You get the time left when downloading from my server, right?
                          I did, at least. (using Firefox 3.0.5 on Ubuntu.)

                          Like I said before, if the code I posted does not work on your server, then there must be a problem with the server.
                          The code works, the link I provided proves that. You just need to figure out why it doesn't work on your server.

                          I suggest you contact your host. Perhaps they will know why this is happening.

                          Comment

                          • tader
                            New Member
                            • Sep 2007
                            • 43

                            #14
                            ok than you for you help ;]

                            Comment

                            Working...