Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2008-05-06, 06:01 PM   #1
Cleo
Subversive filth of the hedonistic decadent West
 
Cleo's Avatar
 
Join Date: Mar 2003
Location: Southeast Florida
Posts: 27,936
Question Forcing movies to download

Is there something I can do with htaccess or something to force a movie to download instead of being viewed in the browser or being streamed to a player?
__________________
Free Rides on Uber and Lyft
Uber Car: uberTzTerri
Lyft Car: TZ896289
Cleo is offline   Reply With Quote
Old 2008-05-06, 07:02 PM   #2
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
I believe to do this you need to alter the content type of the file being served which requires a handler of sorts to do this which can then be hidden with an .htaccess. It will use more cpu than letting apache serve the file.

Code:
<?php
  header("Content-Type: video/x-ms-wmv");
  header('Content-Disposition: attachment; filename="test.wmv"');
  $file=fopen("test.wmv","rb");
  fpassthru($file);
  close($file);
?>
properly wrapped with a mod_rewrite, you could have it automatically parse and hand out files. Let me know and I can come up with something a little closer to what you want.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2008-05-06, 07:17 PM   #3
Cleo
Subversive filth of the hedonistic decadent West
 
Cleo's Avatar
 
Join Date: Mar 2003
Location: Southeast Florida
Posts: 27,936
It's for inside of member's area. Right now the members are told to right mouse click but this seems too complicated for some of them based on help emails.

The mp4 movies can be viewed in the browser but then there are also links to download the mp4 movies plus the m4v and wmv file.

Screen shot
Attached Images
File Type: jpg menu.jpg (53.4 KB, 144 views)
__________________
Free Rides on Uber and Lyft
Uber Car: uberTzTerri
Lyft Car: TZ896289
Cleo is offline   Reply With Quote
Old 2008-05-06, 07:19 PM   #4
Cleo
Subversive filth of the hedonistic decadent West
 
Cleo's Avatar
 
Join Date: Mar 2003
Location: Southeast Florida
Posts: 27,936
I can change around how things are organized but this is how it is being done at the three sites that I manage.

One pic per post so here is the shot of the directory
Attached Images
File Type: png Picture 1.png (57.0 KB, 132 views)
__________________
Free Rides on Uber and Lyft
Uber Car: uberTzTerri
Lyft Car: TZ896289
Cleo is offline   Reply With Quote
Old 2008-05-06, 09:10 PM   #5
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
.htaccess
Code:
RewriteEngine on
RewriteRule vids/(.*) /video.php?video=$1 [L]
video.php
Code:
<?php
  $filename = "/var/www/domain.com/" . $_REQUEST['video'];
  if ( (preg_match("/[a-z0-9\-_]+.(mp4|wmv|mp4a)/i",$_REQUEST['video'])) && 
       (file_exists($filename)) ) {
  header("Content-Type: " . mime_content_type($filename));
  header('Content-Disposition: attachment; filename="' . $_REQUEST['video'] . '"');
  $file=fopen($filename,"rb");
  fpassthru($file);
  close($file);
  } else {
    print "error retrieving file";
  }
?>
Not a lot of error checking in it, file paths will need to be changed, but, this is probably the basics of what you're looking for. Mimetype detection will help, you can fix the preg_match to match the extensions you want to allow. filenames cannot contain more than one . and must be comprised of all letters, numbers, - and _.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2008-05-06, 09:48 PM   #6
Cleo
Subversive filth of the hedonistic decadent West
 
Cleo's Avatar
 
Join Date: Mar 2003
Location: Southeast Florida
Posts: 27,936
That does look exactly like what I'm looking for.

Lets see if I've got this right...
I link to the video.php and the video.php calls up the movie that is specified in its server path and if I have four movies then I make four copies of video.php

I should change this to this for the 3 movie extensions that I use.
Code:
(mp4|wmv|m4v)
Each directory would have its own set of video.php files and each video.php would have the server path to that movie.

I'll try it out tomorrow on the Ana site.
__________________
Free Rides on Uber and Lyft
Uber Car: uberTzTerri
Lyft Car: TZ896289
Cleo is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT -4. The time now is 07:36 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc