You are here: Re: protecting images from view « All PHP « IT news, forums, messages
Re: protecting images from view

Posted by J.O. Aho on 09/28/20 11:42

jaschreiber@gmail.com wrote:
> i'm trying to set up a website where i can post images for only certain
>
> clients to see. so far the whole site works beautifully except the
> image protection... visitors must log in to the system and then are
> only given access to data and images that pertain to them.
>
> the best system that i can come up with is to store the images outside
> of the web directory...

Yes, this is the only way to go (a .htaccess protected directory works too).


> but i'm having trouble figuring out how to
> access the images again.

You will need to use a php page for that and from there call fpassthru()
http://www.php.net/manual/en/function.fpassthru.php

--- image.php ---
<?PHP
/* This is just a simple example and don't take care of security or access
* we assume that all images are png
*/

$image="/full/path/to/" .eregi_replace("/","",$_REQUEST['img']) .".png";
$fp = fopen($image, 'rb');
header("Content-Type: image/png");
header("Content-Length: " . filesize($image));
fpassthru($fp);
exit;

?>
--- eof ---


Now you can call the image in quite the same way as with normal images
<img src="image.php?img=bluegirl">

Now you need to have the image
/full/path/to/bluegirl.png
and it will be shown.

You can add some access checks and so, and when someone who don't have access
to the image wants to see one, you can choose to serve a default image.


//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация