runitzme Posted August 13, 2008 Share Posted August 13, 2008 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! Quote Link to comment Share on other sites More sharing options...
bretticus Posted August 13, 2008 Share Posted August 13, 2008 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! Quote Link to comment Share on other sites More sharing options...
runitzme Posted August 13, 2008 Author Share Posted August 13, 2008 Thank you! You're the best, i will try this and post the results Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.