Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
MP3 force download instead of streaming
Old 04-16-2006, 05:44 PM MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
I am making MP3's avaliable for download. I need a way to link to MP3's without the browser streaming them. I'm using XHTML Strict 1.0 and I need it to validate. I'm happy with just getting the "save as or open" box. Thanks,
Carter De Angelis
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
 
Register now for full access!
Old 04-17-2006, 03:25 AM Re: MP3 force download instead of streaming
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
MP3's don't stream

If the end user has .mp3 set to open immediately they will download and play, if they have .mp3 set as "Confirm open after download" they will see the open/save dialog
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-17-2006, 06:06 PM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
yes, I understand that but I want a way so that they can stream it but the default is download. Or at least that box. Do you understand? I can't have everyone switch it and I'm pretty sure that if they have qt installed the default is to stream.
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Old 04-17-2006, 06:09 PM Re: MP3 force download instead of streaming
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
then you will have to use some server side code to set the MIME type and stream the file out to the user.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-17-2006, 06:19 PM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
do you know how to do that by any chance?
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Old 04-17-2006, 06:26 PM Re: MP3 force download instead of streaming
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Yep


are you going to divulge what serverside code???
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-17-2006, 06:28 PM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
I have no idea what that is. I'm sorry. This is my first site. here's the link. its though godaddy. Its a red hat server that supports lots of stuff. I don't know if its apache or what.



Sorry wrong link

Last edited by carterdea; 04-17-2006 at 06:29 PM..
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Old 04-17-2006, 06:39 PM Re: MP3 force download instead of streaming
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's an Apache server, but it doesn't appear to be PHP enabled according to WebBug, so the answer is you can't on that server.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-17-2006, 06:43 PM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
oh. Godaddy told me that It was PHP and CGI enabled. But I told them I didn't need PHP. So maybe they turned it off. I will check.
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Old 04-17-2006, 06:47 PM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
yeah. Its included with the deluxe hosting. PHP 4 and 5
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Old 04-26-2006, 10:39 PM Re: MP3 force download instead of streaming
CurrentWave's Avatar
Junior Talker

Posts: 4
Location: Right here in front of my Computer
Trades: 0
You can do this many ways, but they don't all work in all browsers/platforms and many of the options out there don't include all the features.

So... here is the best I've found so far

Perl solution -
You would save the code below in a file with the .pl extension or cgi (I used download.cgi below), upload it to your server (FTP) and set the permissions to 755 (you may need to call your host godaddy to help you with these things).

Here is the link you would use for your media -
<a href="http://www.domain.com/download.cgi?ID=file.name">Download File</a>

Code:
#!/usr/bin/perl -wT

use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $files_location;  
my $ID;  
my @fileholder;
$files_location = "/www/g/gcm345/htdocs/MP3/";
$ID = param('ID');

# require file name
if ($ID eq '') {  
print "Content-type: text/html\n\n";  
print "You must specify a file to download.";  
} else {

# If a file name is specified, we want to open that file and 
# assign its contents to a temporary placeholder, and display an error message.
open(DLFILE, "<$files_location/$ID") || Error('open', 'file');  
@fileholder = <DLFILE>;  
close (DLFILE) || Error ('close', 'file');

# Log the number of times each file is downloaded, or an error message.
open (LOG, ">>/www/g/gcm345/htdocs/MP3/dl.log") || Error('open', 'file');
print LOG "$ID\n";
close (LOG);

print "Content-Type: application/x-download\n";
# print "Content-Length: {'Content-length'}\n";  
print "Content-Disposition: attachment;filename=$ID\n\n";
print @fileholder
}

# prrints browser error message
  sub Error {
       print "Content-type: text/html\n\n";
   print "The server can't $_[0] the $_[1]: $! \n";
   exit;
 }
Now this offering works, but it doesn't address client side caching for saving of bandwidth. You also have to create a log file (empty text file) name it dl.log and upload to the dir where your media is. Then change the permissions to 777 on that file.

Also - you can create an .htaccess file (do a search on it for lots of how to) place this file at the root of your hosting account, maybe even one level higher. With this in it -
Code:
Options -indexes

AddType application/octet-stream .mp3 .mpeg

<Files .htaccess>
order allow,deny
deny from all
</Files>
Where .mp3 .mpeg need to be changed to the extension of the type of media you want to download. The other entries are just for security and you can do searches on them for more info - as this post is growing way to long!

And the last option I would submit (but I haven't tried it) is using php like this -

Code:
<?php

$filename = $_GET['file'];

// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
  ini_set('zlib.output_compression', 'Off');

// addition by Jorg Weske
$file_extension = strtolower(substr(strrchr($filename,"."),1));

if( $filename == "" ) 
{
  echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
  exit;
} elseif ( ! file_exists( $filename ) ) 
{
  echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
  exit;
};
switch( $file_extension )
{
  case "pdf": $ctype="application/pdf"; break;
  case "exe": $ctype="application/octet-stream"; break;
  case "zip": $ctype="application/zip"; break;
  case "doc": $ctype="application/msword"; break;
  case "xls": $ctype="application/vnd.ms-excel"; break;
  case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
  case "gif": $ctype="image/gif"; break;
  case "png": $ctype="image/png"; break;
  case "jpeg":
  case "jpg": $ctype="image/jpg"; break;
  default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers 
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();

?>
You would have to save this in file with .php file extension, upload to site, and use this for your link - <a href=" http://www.yoursite.com/force-download.php?file=filepath">

I wish there was a simple, secure and easy solution, but all of those turn out not to work in all browsers or in some other way....

I hope this helps
CurrentWave is offline
Reply With Quote
View Public Profile
 
Old 04-27-2006, 11:18 PM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
ok, so I used the .htaccess one, and I used exactly the code you put, and nothing else, and it is still streaming. I am trying the PHP now but I'm not excited about changing ALL 400 links. I guess I'll use a replace method and fix all of the links I don't want changed.
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Old 05-03-2006, 01:51 AM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
tried the PHP way. It didn't work. It is MP3 files that I need to be downloaded. That might have somthing to do with it.
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Old 05-03-2006, 09:19 AM Re: MP3 force download instead of streaming
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Quote:
Originally Posted by chrishirst
It's an Apache server, but it doesn't appear to be PHP enabled according to WebBug, so the answer is you can't on that server.
Why not? If he can access apache config he can set AddType application/octet-stream .mp3 to have user downloaded it instead of opening in a browser. I'll try to perform this on my machine right now.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-03-2006, 09:22 AM Re: MP3 force download instead of streaming
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Quote:
Originally Posted by mtishetsky
Why not? If he can access apache config he can set AddType application/octet-stream .mp3 to have user downloaded it instead of opening in a browser. I'll try to perform this on my machine right now.
Nope, doesn't work even if I set application/octet-stream. Seems like browser with Quicktime installed (in my case) reads first bytes of file instead of relying on HTTP headers.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-03-2006, 05:41 PM Re: MP3 force download instead of streaming
carterdea's Avatar
Ultra Talker

Posts: 353
Location: Arizona
Trades: 0
I tried the PHP way again. It seems to have worked!!! Except IE doesn't like it occasionally and tries to stream it. But I can live with that if its only occasionally.
Thanks for all of your help.
carterdea is offline
Reply With Quote
View Public Profile Visit carterdea's homepage!
 
Reply     « Reply to MP3 force download instead of streaming
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46393 seconds with 12 queries