fetching images

General discussions related to php

Moderators: macek, egami, gesf

leigh
New php-forum User
New php-forum User
Posts: 10
Joined: Thu Jul 03, 2003 5:20 pm
Location: London, England

fetching images

Postby leigh » Mon Jul 28, 2003 9:15 am

Hi all

I have placed a directory of images outside of my server root so the normal <img src="../../images/pic.jpg" /> will not work. However, I believe a php script could retieve them, can anyone suggest how this might be done?

Many thanks in advance

Leigh

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Mon Jul 28, 2003 10:10 am

<img src="img_getter.php?file_ref=blat_fooey.jpg" />

Code: Select all

$file_ref = '/root/path_to_images/' .$_GET['file_ref'];
if(file_exists($file_ref))
   {
   $tipe = getimagesize($file_ref);
   $header_ext = ($tipe[2] < 4) ? ($tipe[2] < 3) ? ($tipe[2] < 2) ? ($tipe[2] < 1) ? NULL : 'gif' : 'jpeg' : 'png' : NULL;
   if($header_ext !== NULL)
      {
      header("Content-type: image/" .$header_ext);
      readfile($file_ref);
      }
   }


can even add a session test there to stop offsite linking.

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Mon Jul 28, 2003 10:22 am

pootergeist wrote:can even add a session test there to stop offsite linking.


Or just a referrer test.


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests