Page 1 of 1
Video downloads end with .html
Posted: Fri Dec 17, 2010 3:48 am
by floam
On my system video downloads were getting a text/html Content-Type causing Safari to append .html to the end of the filenames. This quick fix got around that.
Code: Select all
--- video.phpold 2010-12-16 19:35:57.194047323 -0800
+++ video.php 2010-12-16 19:38:27.650321752 -0800
@@ -89,6 +89,7 @@
{
$downloadIndex = validInt($_REQUEST['downloadIndex']);
header( "Content-disposition: attachment; filename=".$videoFiles[$downloadIndex]."; size=".filesize($videoFiles[$downloadIndex]) );
+ header( "Content-Type: application/octet-stream" );
readfile( $videoFiles[$downloadIndex] );
exit;
}
Posted: Fri Dec 17, 2010 10:32 pm
by BlankMan
Opera was doing this to me too, might give this a try, thanks.
Posted: Fri Dec 31, 2010 5:37 pm
by mastertheknife
Complete headers would probably work better.
Code: Select all
--- a/web/skins/classic/views/video.php
+++ b/web/skins/classic/views/video.php
@@ -88,7 +88,15 @@ if ( isset($_REQUEST['deleteIndex']) )
if ( isset($_REQUEST['downloadIndex']) )
{
$downloadIndex = validInt($_REQUEST['downloadIndex']);
- header( "Content-disposition: attachment; filename=".$videoFiles[$downloadIndex]."; size=".filesize($videoFiles[$downloadIndex]) );
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: private",false); // required by certain browsers
+ header("Content-Description: File Transfer");
+ header("Content-Disposition: attachment; filename=".$videoFiles[$downloadIndex]);
+ header("Content-Transfer-Encoding: binary");
+ header("Content-Type: application/force-download");
+ header("Content-Length: ".filesize($videoFiles[$downloadIndex]));
readfile( $videoFiles[$downloadIndex] );
exit;
}
EDIT: Fixed missing parenthesis in the code
EDIT 2: Do not use, newer patch in the post below.
mastertheknife.
Posted: Sat Feb 05, 2011 6:25 am
by mastertheknife
I fixed the patch to work for old IE and fixed filenames for Firefox. On my machine the file name was events_1_12487-r1-s1.avi, this is because Firefox doesn't strip paths from the filename but simply replaces them with underscore. I used basename() to strip the path.
Patch was tested on IE6, Opera 10 and Firefox 3.6.
Code: Select all
--- a/web/skins/classic/views/video.php
+++ b/web/skins/classic/views/video.php
@@ -88,7 +88,15 @@ if ( isset($_REQUEST['deleteIndex']) )
if ( isset($_REQUEST['downloadIndex']) )
{
$downloadIndex = validInt($_REQUEST['downloadIndex']);
- header( "Content-disposition: attachment; filename=".$videoFiles[$downloadIndex]."; size=".filesize($videoFiles[$downloadIndex]) );
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: private",false); // required by certain browsers
+ header("Content-Description: File Transfer");
+ header('Content-Disposition: attachment; filename="'.basename($videoFiles[$downloadIndex]).'"'); // basename is required because the video index contains the path and firefox doesn't strip the path but simply replaces the slashes with an underscore.
+ header("Content-Transfer-Encoding: binary");
+ header("Content-Type: application/force-download");
+ header("Content-Length: ".filesize($videoFiles[$downloadIndex]));
readfile( $videoFiles[$downloadIndex] );
exit;
}
Reports from other browsers and versions are welcome.
mastertheknife.
Posted: Sun Feb 06, 2011 4:48 pm
by zoneminder
This is a strange one. In FireFox for me, everything has been working fine and when clicking on the Download link the default actual suggested by FF is to download the file. However applying this change makes FF suggest opening the link rather than downloading it.
That may be by design and other than requiring one more click it doesn't break anything so I will probably apply the patch anyway.
Re: Video downloads end with .html
Posted: Mon Apr 11, 2011 4:48 am
by floam
Probably a better idea to use application/octet-stream than application/force-download. The former is the official type for arbitrary byte data and the latter just works as a side effect. Best would be figuring out what is actually being sent and choose the correct MIME, but that's not as trivial.