LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2008, 05:08 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
html: is there a way to tell a browser what application to use for a video?


At my office, we have mplayer-plugin handling all our video files through the web browser.

The short question is: can I tell the browser which application to use (or to try) before it uses the preference setting?

The slightly longer question is: when someone clicks a direct link to an mp4, I want a particular application to launch it rather than mplayer-plugin. I know I can do this by editing the Iceweasel (firefox) prefs, but can I do it without altering the prefs, i.e. directly in the html/javascript?

To be clear, I'm not looking for another application to handle embedded objects, I'm looking for something to handle direct links to files, i.e.

< a href = 'foo.mp4' > link < /a > (this is what I'm asking about)

as opposed to

< embed src='foo.mp4' width='$x' height='$y'></embed> (this, I don't care as much about, but if it solves the problem, I'll take it).

I'm also not opposed to use object tags if that will do it.

Thanks
 
Old 04-07-2008, 06:55 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
I certainly can't think of any way to do it through HTML. HTML is only bringing the content to the client, it doesn't actually play it. It is up to the configuration in the browser to know what programs to associate with what file extensions.
 
Old 04-07-2008, 07:26 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by MS3FGX View Post
I certainly can't think of any way to do it through HTML. HTML is only bringing the content to the client, it doesn't actually play it. It is up to the configuration in the browser to know what programs to associate with what file extensions.
hmm... I figured as much.

In the mean time, I'm using this method of forcing a download - essentially just loading up a header that the browser treats as a download. It's a modified version of something I found on the web. This way, someone can chose the application to view the thing because they have the "Open With.." option.

PHP 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>Error Downloading file</title>\n";
  echo 
"<body>ERROR: download file not specified.</body></html>\n";
  exit;
} elseif ( ! 
file_exists$filename ) ) 
{
  echo 
"<html><title>Error Downloading</title>\n";
  echo 
"<body>ERROR: File not found.</body></html>\n";
  exit;
};
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: application/force-download");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: quoted-printable");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();

?>
then I use it like so:

< a href='./force_download.php?file=foo.mp4' >


This does work, but it's not very elegant. Would prefer a better solution.
 
Old 04-07-2008, 08:53 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
I think you can configure the server to identify the file as something to download. According to this page putting
Code:
AddType application/octet-stream    .mp4
in the .htaccess file should work (if you're using Apache that is). I wouldn't expect to able to choose which application, since that would pretty much allow any website to run arbitrary code on your computer...
 
Old 04-07-2008, 09:23 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by ntubski View Post
I think you can configure the server to identify the file as something to download. According to this page putting
Code:
AddType application/octet-stream    .mp4
in the .htaccess file should work (if you're using Apache that is). I wouldn't expect to able to choose which application, since that would pretty much allow any website to run arbitrary code on your computer...
ahh... good idea. Thanks!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser cannot load Apache index.html tekmann33 General 7 02-19-2007 03:57 PM
What Application for Compiled HTML bdprem Linux - Software 6 02-07-2007 08:07 AM
Open HTML file in default browser through C++ Last Attacker Linux - General 10 10-20-2005 12:32 PM
Change html application... vi0lat0r Linux - General 2 04-08-2004 07:27 AM
simple html browser tda Programming 5 05-20-2002 11:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration