Results 1 to 24 of 24

Thread: Option to download OR play a mp3
      
   

  1. #1
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Cool 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

  2. #2
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  3. #3
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default 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

  4. #4
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default Re: Option to download OR play a mp3

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

  5. #5
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default 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?

  6. #6
    Watdaflip's Avatar
    Watdaflip is offline Major General
    Join Date
    Sep 2005
    Location
    Cincinnati, Ohio
    Posts
    2,119

    Default 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

  7. #7
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  8. #8
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default 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

  9. #9
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  10. #10
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default 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

  11. #11
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  12. #12
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Post 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

  13. #13
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  14. #14
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default 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 at 10:27 AM. Reason: added a point of interest

  15. #15
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default 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!


  16. #16
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default Re: Option to download OR play a mp3

    hi it's me again
    everything is working great for mp3's but still got problems with .wav files. won't download them? is the download.php code above only for mp3's?
    thanx

  17. #17
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Option to download OR play a mp3

    The code is for ANY type of file. Make sure you have no mistakes.
    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!


  18. #18
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default Re: Option to download OR play a mp3

    i really have no mistakes
    it downloads all my mp3 files and not any of my wav files
    ?

  19. #19
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Option to download OR play a mp3

    Please create and provide a link to download a wav file. as a test
    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!


  20. #20
    AWOL is offline Private First Class
    Join Date
    Sep 2006
    Posts
    5

    Default Re: Option to download OR play a mp3

    I too have been trying to set up downloads for the public to access. Thanks so much for the information in this thread. However, I am getting an error message:
    Warning: Unexpected character in input: ' ' (ASCII=11) state=1 in /home/tqjhyvg/public_html/download.php on line 4

    Parse error: syntax error, unexpected T_VARIABLE in /home/tqjhyvg/public_html/download.php on line 4

    Can you help? Thanks so much.

  21. #21
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,115

    Default Re: Option to download OR play a mp3

    You have probably a mistake (missing ; ???) in line 3
    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!


  22. #22
    AWOL is offline Private First Class
    Join Date
    Sep 2006
    Posts
    5

    Default Re: Option to download OR play a mp3

    Thanks for you answer. I copy and paste the php again as it is above. This time it does give the option from the site to open or save, but when you open the player and press play, it does not play.

  23. #23
    Jacho is offline Corporal
    Join Date
    Oct 2007
    Posts
    13

    Default Re: Option to download OR play a mp3

    Quote Originally Posted by Jacho View Post
    i really have no mistakes
    it downloads all my mp3 files and not any of my wav files
    ?
    hi navalDesign,
    i figured out what I was doing wrong
    i was uploading the file to the server as .WAV (uppercase) and in the script i was writing .wav (lower case)
    Thank you for all your time & help

  24. #24
    VodaHost's Avatar
    VodaHost is offline General & Forum Administrator
    Join Date
    Mar 2005
    Location
    Wilmington, Delaware USA
    Posts
    11,428

    Default Re: Option to download OR play a mp3

    thread closed

    VodaHost

    Your Website People!
    1-302-283-3777 North America / International
    07031847328 / United Kingdom

    ------------------------

    Top 3 Best Sellers

    Web Hosting - Unlimited disk space & bandwidth.

    Reseller Hosting - Start your own web hosting business.

    Search Engine & Directory Submission - 300 directories + (Google,Yahoo,Bing)



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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49