GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Can you configure Apache to do this? (https://gfy.com/showthread.php?t=1045053)

Bladewire 11-09-2011 08:40 AM

Can you configure Apache to do this?
 
Make Apache play .mp4 files as usual but

make Apache download .MP4 files to the users computer.

Is this possible? If so, how?

Thanks for your help :thumbsup

darksoul 11-09-2011 08:57 AM

The only way I can think of is setting a different mime type for MP4 files.

Bladewire 11-09-2011 09:08 AM

Quote:

Originally Posted by darksoul (Post 18547249)
The only way I can think of is setting a different mime type for MP4 files.

Ok so changing the mime type for .MP4 , but keeping .mp4 as it is, could force downloads of .MP4 ?

What I'm trying to do is have a solution where I have one copy of each video file. Where .mp4 plays in my video player for member and when they click the download link, it will link to a .MP4 copy that downloads automatically.

Bladewire 11-09-2011 10:01 AM

bump :helpme :thumbsup

SmokeyTheBear 11-09-2011 10:33 AM

you could use htaccess like this in the folder with the videos

Code:

RewriteEngine on
 RewriteRule ^(.*)\.MP4 mp4.php?x=$1 [nc]

this makes all requests for capital letter version "example.MP4" go to a file called mp4.php

Code:

<?php
$x = $_GET['x'];
$file = "$x.mp4";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
} else {
echo "bad request";
}
?>


Bladewire 11-09-2011 11:58 AM

Quote:

Originally Posted by SmokeyTheBear (Post 18547515)
you could use htaccess like this in the folder with the videos

Code:

RewriteEngine on
 RewriteRule ^(.*)\.MP4 mp4.php?x=$1 [nc]

this makes all requests for capital letter version "example.MP4" go to a file called mp4.php

Code:

<?php
$x = $_GET['x'];
$file = "$x.mp4";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
} else {
echo "bad request";
}
?>



This is great THANK YOU!


Before reading your post I came across a recomendation to add this to my .htaccess

AddType application/octet-stream .mp4
<FilesMatch "\.(docx?|txt|mp4?)$">
Header add Content-Disposition "attachment"
</FilesMatch>

So far what this does is allows my jwplayer to play .mp4 files, but when a link with an .mp4 file is clicked, the user is prompted to download the file. So I don't need two copies of the video file.

Do you see any drawback to this? I'm not big on programming and have no idea if this doesn't work for everyone.

fris 11-09-2011 01:20 PM

dont you want to be able to embed mp4?

SmokeyTheBear 11-09-2011 02:05 PM

Quote:

Originally Posted by Squirtit (Post 18547779)
This is great THANK YOU!


Before reading your post I came across a recomendation to add this to my .htaccess

AddType application/octet-stream .mp4
<FilesMatch "\.(docx?|txt|mp4?)$">
Header add Content-Disposition "attachment"
</FilesMatch>

So far what this does is allows my jwplayer to play .mp4 files, but when a link with an .mp4 file is clicked, the user is prompted to download the file. So I don't need two copies of the video file.

Do you see any drawback to this? I'm not big on programming and have no idea if this doesn't work for everyone.

my method is the same you just reference "file.MP4" for download and "file.mp4" for jwplayer , it pulls the same video you dont need 2 videos

but really you just need the htaccess you posted because the player will stream it either way

Bladewire 11-09-2011 03:24 PM

Quote:

Originally Posted by fris (Post 18547998)
dont you want to be able to embed mp4?

Yes I definately need to embed.

This works for me on Chrome and Internet Explorer. Click here to see an example.

Does this embed and download the same file for you guys too?

If not, what browser and OS are you using?

I really appreciate the help :thumbsup


.

Tempest 11-09-2011 03:31 PM

Works for me in Opera.... but you might have issues with cellphones (androids) playing the video as I think they need to see the proper mime type. That's one of the reasons trying to "fake it" in apache etc isn't done and ppl have to right click to download or run the download thru a separate script.

raymor 11-09-2011 03:54 PM

Quote:

Originally Posted by SmokeyTheBear (Post 18547515)
you could use htaccess like this in the folder with the videos

Code:

RewriteEngine on
 RewriteRule ^(.*)\.MP4 mp4.php?x=$1 [nc]

this makes all requests for capital letter version "example.MP4" go to a file called mp4.php

Code:

<?php
$x = $_GET['x'];
$file = "$x.mp4";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
} else {
echo "bad request";
}
?>


Do NOT do that in PHP. Similar code in PHP almost always has three major bugs.
Instead set the headers in the .htaccess.

raymor 11-09-2011 03:59 PM

Quote:

Originally Posted by SmokeyTheBear (Post 18547515)
you could use htaccess like this in the folder with the videos

Code:

RewriteEngine on
 RewriteRule ^(.*)\.MP4 mp4.php?x=$1 [nc]

this makes all requests for capital letter version "example.MP4" go to a file called mp4.php

Code:

<?php
$x = $_GET['x'];
$file = "$x.mp4";

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
} else {
echo "bad request";
}
?>


Do NOT read and print videos in PHP. Similar code in PHP almost always has three major bugs.
Instead set the headers in the .htaccess.
Smokey did manage to halfway avoid one bug, so his implementation has only 2 1/2 major issues. That's definitely better than most people do.

Still remaining is the big which for about a year caused one popular CMS to crash servers fairly regularly and this code too will crash your server when it gets busy. It also has a glaring security hole.

Bladewire 11-09-2011 04:18 PM

Quote:

Originally Posted by raymor (Post 18548356)
Do NOT read and print videos in PHP. Similar code in PHP almost always has three major bugs.
Instead set the headers in the .htaccess.
Smokey did manage to halfway avoid one bug, so his implementation has only 2 1/2 major issues. That's definitely better than most people do.

Still remaining is the big which for about a year caused one popular CMS to crash servers fairly regularly and this code too will crash your server when it gets busy. It also has a glaring security hole.

WOW ouch! Thanks for the tip Ray I appreciate that.

Quote:

AddType application/octet-stream .mp4

<FilesMatch "\.(docx?|txt|mp4?)$">
Header add Content-Disposition "attachment"
</FilesMatch>
The above code seems to do the trick in browsers with the longtail video player.

However on my IPad no video shows, only the "download" graphic appears, and when clicked on, it plays the video.

On my Android phone no video shows, only the "download" graphic appears, and when click on, it downloads the video to the phone without viewing.

So maybe if I adjust the longtail player setting to be html5 compatible it could fix this problem?

Thanks for your input I really appreciate it :thumbsup

raymor 11-09-2011 09:52 PM

Quote:

Originally Posted by Squirtit (Post 18548408)
WOW ouch! Thanks for the tip Ray I appreciate that.



The above code seems to do the trick in browsers with the longtail video player.

However on my IPad no video shows, only the "download" graphic appears, and when clicked on, it plays the video.

On my Android phone no video shows, only the "download" graphic appears, and when click on, it downloads the video to the phone without viewing.

So maybe if I adjust the longtail player s etting to be html5 compatible it could fix this problem?

Thanks for your input I really appreciate it :thumbsup

What you can do is use rewrite to call the same file as both mp4 and MP4. So long as you're using rewrite anyway, you can also use it to set the content type. Further, you could add a Content-Disposition header. I'm driving at moment so I can't go through tbe exact code, but that can point you in the right direction.

raymor 11-09-2011 09:57 PM

By the way, what any of this does is SUGGEST to the browser that a file could be saved in the one case or played in the other case. There is absolutely no forcing going on. You can't MAKE them save the file to the hard drive. As far as you know, they may be on a diskless system that doesn't even HAVE a hard drive. You're merely suggesting an appropriate way the file could be handled.

SmokeyTheBear 11-09-2011 10:16 PM

Quote:

Originally Posted by raymor (Post 18549046)
By the way, what any of this does is SUGGEST to the browser that a file could be saved in the one case or played in the other case. There is absolutely no forcing going on. You can't MAKE them save the file to the hard drive. As far as you know, they may be on a diskless system that doesn't even HAVE a hard drive. You're merely suggesting an appropriate way the file could be handled.

actually my method includes nazi skinhead enforcers who will actually visit your house and force you to download it.. if you don't have a hard drive they drive you to the store to buy one.

raymor 11-09-2011 10:21 PM

Quote:

Originally Posted by SmokeyTheBear (Post 18549075)
actually my method includes nazi skinhead enforcers who will actually visit your house and force you to download it.. if you don't have a hard drive they drive you to the store to buy one.

Does the automatic forfeit for triggering Godwin's law apply to jokes?

SmokeyTheBear 11-09-2011 10:44 PM

Quote:

Originally Posted by raymor (Post 18549085)
Does the automatic forfeit for triggering Godwin's law apply to jokes?

the south park "grace period" has expired on using nazi's in jokes, it is ok now..


All times are GMT -7. The time now is 07:07 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123