Jump to content

How to make a php page act like an image?


acroporas

Recommended Posts

I want to hide the real location and file name of the images used on my site.

instead of
[code]<img src="/picture.jpg">[/code]

I would use.
[code]<img src="/image.php">[/code]

Right now I have something like the following for image.php:
[code]<? header("Location: http://www.server.com/picture.jpg"); ?>[/code]

It works in that picture shows up as it on the page when I use. <img src="/image.php">

But if you enter http://www.server.com/image.php into the address bar, rather than just showing the picture, the address is automatically changed to the pictures real address (http://www.server.com/picture.jpg)

Is there a way to make image.php stay in the address bar, and just show the picture as if image.php was actually a .jpg file? 
Link to comment
Share on other sites

You could try something like this...

[code]
<?php

  header('Content-type: image/jpeg');
  readfile('picture.jpg');

?>
[/code]

You can imagine how passing GET (or POST) variables to such a script could enable to you to select from your various images...

EDIT: Tested and Works.  :)
Link to comment
Share on other sites

Thanks, yes, that does exactly what I wanted it to.  And yes, I was planning on using the same script to display all images, I was just trying to get it to work with one image first.  Here is the full code I will use.

[code]
Two numeric variables are passed via GET.  $Gallery and $Image

<?
$count=0;
foreach( Glob("*") as $poten )
  {
if ( is_dir($poten) )
  {
$count += 1;
$folders[$count] = $poten;
  }
  }
sort($folders);

if ( is_dir($folders[$Gallery]) )
  {
chdir($folders[$Gallery]);

$dir=Glob("{*.jpg,*.JPG}",GLOB_BRACE);
sort($dir);

if ( is_file("$dir[$Image]") )
  {
header('Content-type: image/jpeg');
readfile("http://server.com/images/$folders[$Gallery]/$dir[$Image]");
  }
else
  {
header('Content-type: image/jpeg');
readfile("http://server.com/images/badimage.jpg");
  }
  }
else
  {
header('Content-type: image/jpeg');
readfile("http://server.com/images/badimage.jpg");
  }

?>
[/code]
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.