Creating two alternatives: streaming or downloading

  • thenitelite
  • Novice
  • Novice
  • thenitelite
  • Posts: 19
  • Loc: Kansas

Post 3+ Months Ago

Ok some of you, if not most, know of thenitelite.net website -- which I am currently working on. We've only been up for a couple months this year and still learning all the tricks. My question, to you, is what is the source code (either JS or HTML) that will allow a user of my website to download audio files, or stream them? I'd like to be able to have two different choices... what are my options?

Thanks
  • thenitelite
  • Novice
  • Novice
  • thenitelite
  • Posts: 19
  • Loc: Kansas

Post 3+ Months Ago

anyone? I'm somewhat stumped on this...
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I believe to download an audio file you just link to it like you would link any file. So if you file was music.mp3 you would link to it as:

Code: [ Select ]
<a href="music.mp3">My MP3 music file</a>


As far as streaming I am not sure how you would do that.
  • thenitelite
  • Novice
  • Novice
  • thenitelite
  • Posts: 19
  • Loc: Kansas

Post 3+ Months Ago

Actually you'd think it would work, but 'a href' actually launches the default player (i.e. winamp, wmp, etc) and plays it...

ugh.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Oh, so you want it so that when they click on it, it will prompt them to "save as" a file somewhere on their computer?
  • thenitelite
  • Novice
  • Novice
  • thenitelite
  • Posts: 19
  • Loc: Kansas

Post 3+ Months Ago

Bigwebmaster wrote:
Oh, so you want it so that when they click on it, it will prompt them to "save as" a file somewhere on their computer?


Exactly. That little download window that prompts either to save or open the file... or have two different links, one where if clicked it streams the file and plays it and the other link where it automatically prompts the save location/name
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

well, try zipping the file first, that would make the file download by making a link to it, or you could put a console into your webpage like this:
Code: [ Select ]
<embed src="*http://link to music file*" autostart=false loop=false height=62 width=350 controls="smallconsole">

this would make a console in th webpage and would load whilst the viewer is on you site.
i used it on mine
http://www.stormhosting.cjb.com/users/kalbal
on the music bit, that is my very first site i made, it is pretty old now, and i am unsure if the links still work

hope it helps :D
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

A simple solution would be to instruct viewers to right-click the link and choose "save target as", then for your link use a code similar to this:

Code: [ Select ]
<A HREF="anMP3file.mp3" onClick="alert('No, I said RIGHT click!! Then select -- save target as'); return false;">Right click to download this file to your computer </A>


This will pop up an alert that they did it wrong. (What's wrong with them anyway, can't they read! *lol)
  • Nucleo
  • SausagePorkPie
  • Mastermind
  • User avatar
  • Posts: 2297
  • Loc: UK - England

Post 3+ Months Ago

hehe, good point :P, if i were to re-do my website i would .zip the file instead of stream it, saves up space and they dont half load the file and move onto another, using up bandwidth
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23455
  • Loc: Woodbridge VA

Post 3+ Months Ago

The .zip file's not a bad idea, if all you want to do is save it to disc, but it appears thenitelite would like the option for both, and if all you have is a zip, then streaming won't be available. Of, course you could have both files, but face it -- there's a lot of novices out there who wouldn't have a clue how to unzip a file. Sorta need to take the audience into consideration.
  • cw_north
  • Born
  • Born
  • cw_north
  • Posts: 3

Post 3+ Months Ago

If your host has php, you can try this code to force a download. I found it on the web - look for "noleech" in Google.

On mypage.html, have
Code: [ Select ]
<a href="downloader.php?op=thing1">Thing1.mp3</a>
<a href="downloader.php?op=thing2">Thing2.jpg</a>
  1. <a href="downloader.php?op=thing1">Thing1.mp3</a>
  2. <a href="downloader.php?op=thing2">Thing2.jpg</a>


Then create a file called downloader.php and paste this in.
I commented out
Code: [ Select ]
//if (getenv("HTTP_REFERER") == $validreferer) {

because it wasn't working for me. The code works fine without.
Add your files to the list inside, and you're set to go.

Code: [ Select ]
<?php
// Script that allows you to allow a download to a file outside of the web directory.
// Obviously, this has potential security risks. So DO NOT allow people to specify path or filename.


$go = 0; // assume failure
$redirectpage = "http://www.mysite.com/oops.htm"; //where to go if the query is invalid
$validreferer = "http://www.mysite.com/linktodownloadpage.htm"; // allowed calling pages

// check for valid refererring address... use getenv to prevent people from passing it on the command line.
//if (getenv("HTTP_REFERER") == $validreferer) {
    $go=1;
//    }


// format is:
//
//    "NAME" => "path|filename";
//

$files = array (
    "thing1"    => "../soundclips|thing1.mp3",
    "thing2"    => "misc/pics|thing2.jpg",
    "thing3"    => "misc|thing3.txt"
);

list($path,$filename) = explode("|","$files[$op]");

if ($path == "" || $filename == "") {$go = 0;}


// this is the actual dump part.
if ($go == 1)
{

    // no need to go anywhere after this, since the file downloads straight from the link.
    header("Expires: Mon, 26 Jul 2001 05:00:00 GMT"); // always expired
    header("Last-Modified: " . gmdate("D, d M Y H:i:i") . " GMT"); // always just modified
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Cache-control: private");
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=$filename");
    header("Content-Length: " . filesize("$path/$filename"));

    $fp=fopen("$path/$filename","r");
    print fread($fp,filesize("$path/$filename"));
    fclose($fp);
    exit();
}

// use a header redirect. You CANNOT add any HTML before this.

if ($go == 0)
{
    header("Location: $redirectpage");
}
?>
  1. <?php
  2. // Script that allows you to allow a download to a file outside of the web directory.
  3. // Obviously, this has potential security risks. So DO NOT allow people to specify path or filename.
  4. $go = 0; // assume failure
  5. $redirectpage = "http://www.mysite.com/oops.htm"; //where to go if the query is invalid
  6. $validreferer = "http://www.mysite.com/linktodownloadpage.htm"; // allowed calling pages
  7. // check for valid refererring address... use getenv to prevent people from passing it on the command line.
  8. //if (getenv("HTTP_REFERER") == $validreferer) {
  9.     $go=1;
  10. //    }
  11. // format is:
  12. //
  13. //    "NAME" => "path|filename";
  14. //
  15. $files = array (
  16.     "thing1"    => "../soundclips|thing1.mp3",
  17.     "thing2"    => "misc/pics|thing2.jpg",
  18.     "thing3"    => "misc|thing3.txt"
  19. );
  20. list($path,$filename) = explode("|","$files[$op]");
  21. if ($path == "" || $filename == "") {$go = 0;}
  22. // this is the actual dump part.
  23. if ($go == 1)
  24. {
  25.     // no need to go anywhere after this, since the file downloads straight from the link.
  26.     header("Expires: Mon, 26 Jul 2001 05:00:00 GMT"); // always expired
  27.     header("Last-Modified: " . gmdate("D, d M Y H:i:i") . " GMT"); // always just modified
  28.     header("Cache-Control: no-store, no-cache, must-revalidate");
  29.     header("Cache-Control: post-check=0, pre-check=0", false);
  30.     header("Pragma: no-cache");
  31.     header("Cache-control: private");
  32.     header("Content-Type: application/octet-stream");
  33.     header("Content-Disposition: attachment; filename=$filename");
  34.     header("Content-Length: " . filesize("$path/$filename"));
  35.     $fp=fopen("$path/$filename","r");
  36.     print fread($fp,filesize("$path/$filename"));
  37.     fclose($fp);
  38.     exit();
  39. }
  40. // use a header redirect. You CANNOT add any HTML before this.
  41. if ($go == 0)
  42. {
  43.     header("Location: $redirectpage");
  44. }
  45. ?>


What I'd like to know is - how can I disable the Open button in the File Download popup, and have just the Save button? Is that possible?
  • b_heyer
  • Web Master
  • Web Master
  • User avatar
  • Posts: 4581
  • Loc: Maryland

Post 3+ Months Ago

Nope.
  • cw_north
  • Born
  • Born
  • cw_north
  • Posts: 3

Post 3+ Months Ago

oh. :(

Thanks anyways.
  • michael_ewald
  • Born
  • Born
  • michael_ewald
  • Posts: 1

Post 3+ Months Ago

When you reference the link like that, it is downloading the file, not streaming it. :D

Check your temp file dir and you will see it.

If you want to stream check out http://developer.apple.com/darwin/projects/streaming/ or http://www.netjuke.org/
That gives you so many options.

Thanks,
Michael Ewald

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: No registered users and 56 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.