Re: Block direct image loads but allow them in PHP

From: Date: Wed, 19 Feb 2003 01:46:19 +0000
Subject: Re: Block direct image loads but allow them in PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-136097@lists.php.net to get a copy of this message
So I implemented this the other day and got excited as it worked...sort of. My code is very similar to the link that you suggested. This is the script that I would call from within an <img src=...imagePiper.php?i=blahblah>: if(isset($i)) { //codeImageURL decodes $i into an image path that we can work with $link=codeImageURL($i); if($link!="" && (isAdmin() || !isThisFileBlocked($link))) { header("Cache-control: private"); header("Content-type: image/jpg"); header("Content-Disposition: attachment; filename=".$link); $fp = fopen($link, 'r'); fpassthru($fp); fclose($fp); } else echo "Error: Couldn't decode image URL<br>\n"; } This code seems to work in *some* browsers, but not all. That is, in some browsers, images will display just fine. In other browsers (i.e. Some flavors of IE on the PC) I just get red x's. I cannot identify any particular commonality among them and I was wondering if you have any suggestions to make this work? Thanks in advance! On 02/15/03 8:44 PM, "Justin French" <justin@indent.com.au> wrote: > Using Apache's main config file (or at a per-directory level using a > .htaccess file), you need to black all .jpg, .jpeg, .gif, .png, .bmp, etc > etc files from being *directly* served via http. > > I'm not too good with Apache yet, but an example would be: > > <Files ~ "\.jpg$"> > Order Allow,Deny > ... > > Then you need to create a script called image.php which: > > a) accepts file=xxxx.xxx in the URL ($_GET) > b) sets the appropriate image header > c) passes the image file though > > Instead of you calling > <img src='imageDir/picture.jpg' /> > > You would call > <img src='image.php?file=imageDir/picture.jpg' /> -m^2 __________ Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread! __________

« previous php.general (#136097) next »