Jump to content

How do you stream images/videos in browser...


runitzme

Recommended Posts

Hello all!

 

I'm trying to make a php download script without the force download. So it basically achieve the same functionality as if you would click a raw http link. exp:

 

http://domain-name.com/image.jpg    would get you the image inside the browser(while a force-downlaod script would make you save it to your computer.)

 

I'm trying to do this because I want it to give some validation and security access to my media files before they are viewed...

 

Any help would be appreciated,

thanks in advance!

Link to comment
Share on other sites

Here's one way out of many.

 

What you need to do is have one php script always return the image file. Again, one is...

 

<?php
header( "Content-type: image/gif" );
@readfile( "/your/replacement/image/filepath.gif" );
?>

 

Now, you have to know what type of file you have before doing this (there are many php functions to automate this.) In this case, I know that the image is a gif file.

 

Also, the path to the file being read does not have to be accessible via your website (in fact it's more secure if it's not!) Another thing you should do is have a random key and a hard to guess static key in order to know which image to show.

 

So your page that shows the image has a tag like

 

<html>
<img src=''php_script_path_above.php?statickey=2h346526987278465i2364&randomkey=2gh35ghg346g2gh2hg546hg3">
</html>

 

The static key can be looked up to correspond to the image sought (you might md5 hash the file name for example. Or make a random hash and store it with the real file path in your code or database.) The purpose of the random key is to bust the browser or any proxy caches.

 

Finally, you could use a session to do away with the static key (more secure since your application should "know" which image to show before the page load which calls the image in html code. No chance to memorize the static key!)

 

Good luck! 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.