Option to download OR play a mp3

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Jacho
    Corporal

    • Oct 2007
    • 13

    Option to download OR play a mp3

    I want to give the public an option to EITHER download an mp3 to their computers OR listen to it on site using the Windows Media Player.
    The problem is that when I click on the text link to download it to the computer, it automatically opens it in the Media Player..... If i create it as a .zip file, I am going to have to upload it twice (once as a zip and once as mp3 to listen to)..... If I right click the text link, that works, but it is not proffesional enough.....If a create the link as 'file://' instead of 'http://' , the link doesnt work...
    Is there a way that I can upload the file ONCE and have the option of a download OR real time listen?

    I am new so I dont have a site up and running yet, but my Client ID# is 18412

    Thanx
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: Option to download OR play a mp3

    You need a script for that:

    <?php

    $filename = $_GET['filename'];
    $filesize = $_GET['filesize'];
    $filetype = $_GET['filetype'];
    header("Pragma: public");
    header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false);
    header("Content-type: Application/ $filetype");
    header("Content-Disposition: attachment; filename=$filename");
    header("Content-Description: Download PHP");
    header("Content-Length: $filesize");
    header("Content-Transfer-Encoding: binary");
    readfile($filename);
    set_time_limit(0);

    ?>

    Copy the code, paste it in notepad, and Save As "download.php". Upload it in your site.

    Now, in your page create the Link for playing, as normally, and a second link, for download, as

    download.php?filename=realfilename&filesize=realfilesize&filetype=realfiletype

    realfilename and realfilesize and realfiletype MUST be the actual name, size and type of your file.

    Of course, this will only work when published, as it is in php
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • Jacho
      Corporal

      • Oct 2007
      • 13

      #3
      Re: Option to download OR play a mp3

      wow...thank you..
      I will try it out

      thank you so much for the quick reply
      keep well

      Comment

      • Jacho
        Corporal

        • Oct 2007
        • 13

        #4
        Re: Option to download OR play a mp3

        IT WORKS !!!!!!!
        thank you so so much
        I really appreciate it

        Comment

        • Jacho
          Corporal

          • Oct 2007
          • 13

          #5
          Re: Option to download OR play a mp3

          the file is downloading but it is not there...
          seems to have gotten corrupt along the way?

          Comment

          • Watdaflip
            Major General

            • Sep 2005
            • 2116

            #6
            Re: Option to download OR play a mp3

            Most likely either the filesize isn't correct (make sure its in bytes, not kb or mb), or the filename of the file on your website isn't correct (although if its a problem with the filename it should give you an error)

            Register/Login Script
            Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

            Comment

            • navaldesign
              General & Forum Moderator

              • Oct 2005
              • 12080

              #7
              Re: Option to download OR play a mp3

              Sorry, it has been my mistake. I edited the third and fourth line as the ones i gave you are from a script of mine that retrieves the details from a database, which is not your case. Replace the entire code and try it again.
              Navaldesign
              Logger Lite: Low Cost, Customizable, multifeatured Login script
              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

              Comment

              • Jacho
                Corporal

                • Oct 2007
                • 13

                #8
                Re: Option to download OR play a mp3

                where is the new edited script ?

                also, would this be correct as an example:
                "testing.mp3" which is 36kb
                download.php?filename=testing.mp3&filesize=36000&filetype=mp3

                Thanx

                Comment

                • navaldesign
                  General & Forum Moderator

                  • Oct 2005
                  • 12080

                  #9
                  Re: Option to download OR play a mp3

                  I edited directly the original post. The difference is in the third and fourth line.

                  In your computer, browse the folder where your mp3 is. Right click on it, Properties, and it will display the file properties. Among them the size, which will be something like (as an example) 35897 bytes. This is the number you need to pass over to the script, not a rounded value.

                  As for the file type, if your file is mp3, then that's the value that you need to pass to the script. So it would be:

                  download.php?filename=testing.mp3&filesize=35897&filetype=mp3

                  Make SURE the file name contains no blanks (whitespaces)
                  Navaldesign
                  Logger Lite: Low Cost, Customizable, multifeatured Login script
                  Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                  DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                  Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                  Comment

                  • Jacho
                    Corporal

                    • Oct 2007
                    • 13

                    #10
                    Re: Option to download OR play a mp3

                    I copied the text and checked the bytes:
                    thsi is the real code:

                    download.php?filename=anybody.mp3&filesize=37393&filetype=mp3

                    still not working?
                    the test site is www.mcpbm.com

                    thank you

                    Comment

                    • navaldesign
                      General & Forum Moderator

                      • Oct 2005
                      • 12080

                      #11
                      Re: Option to download OR play a mp3

                      I will back to you within 1 hr as i am busy now, and we will sort this out.
                      Navaldesign
                      Logger Lite: Low Cost, Customizable, multifeatured Login script
                      Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                      DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                      Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                      Comment

                      • Jacho
                        Corporal

                        • Oct 2007
                        • 13

                        #12
                        Re: Option to download OR play a mp3

                        I think i found the problem, but I dont know how to solve it
                        In the same folder as my mp3 file there is file called "error_log".
                        In there the following message appears every time i try the link:

                        [16-Oct-2007 08:48:59] PHP Warning: readfile() has been disabled for security reasons in //public_html/test/download.php on line 15

                        how do I stop this problem? Is it through my cpanel?

                        Thanx

                        Comment

                        • navaldesign
                          General & Forum Moderator

                          • Oct 2005
                          • 12080

                          #13
                          Re: Option to download OR play a mp3

                          readfile should not be disabled. If it is, please submit a suppor ticket asking for it to be enabled. I believe VH staff can enable it in the php settings.
                          Navaldesign
                          Logger Lite: Low Cost, Customizable, multifeatured Login script
                          Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                          DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                          Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                          Comment

                          • Jacho
                            Corporal

                            • Oct 2007
                            • 13

                            #14
                            Re: Option to download OR play a mp3

                            thank you very much for all your help
                            VH inserted a file called "php.ini" into my public_html directory and it all works fine
                            (a guy from the IT department said that if I replaced readfile() with include() it would also work but that it is more secure to stick to readfile())

                            thanks again
                            Last edited by Jacho; 10-17-2007, 10:27 AM. Reason: added a point of interest

                            Comment

                            • navaldesign
                              General & Forum Moderator

                              • Oct 2005
                              • 12080

                              #15
                              Re: Option to download OR play a mp3

                              Hi Jacho,

                              no, include() will not work. You see include() embedds the file content in your script, whilst readfile() reads the content, and pushes it through the header command to the users browser.
                              Navaldesign
                              Logger Lite: Low Cost, Customizable, multifeatured Login script
                              Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                              DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                              Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                              Comment

                              Working...
                              X