Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Forcing movies to download (http://www.greenguysboard.com/board/showthread.php?t=46915)

Cleo 2008-05-06 06:01 PM

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?

cd34 2008-05-06 07:02 PM

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:

  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.

Cleo 2008-05-06 07:17 PM

1 Attachment(s)
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

Cleo 2008-05-06 07:19 PM

1 Attachment(s)
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

cd34 2008-05-06 09:10 PM

.htaccess
Code:

RewriteEngine on
RewriteRule vids/(.*) /video.php?video=$1 [L]

video.php
Code:

  $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 _.

Cleo 2008-05-06 09:48 PM

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.


All times are GMT -4. The time now is 04:59 AM.

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