Web Hosting Talk







View Full Version : loading images with a PHP extension


dutchee
09-11-2004, 11:38 AM
Hi,


I'm looking for a PHP script or a Perl/CGI script which you can use to upload and host images in .gif/.jpg/.png format. But the link to the image will carry not these extensions, just a string with chars like without extension http://www.domain-name.com/images/?=12345abcde
or with a PHP extension:
http://www.domain-name.com/images/12345abcde.php

And an URL like this will just load the image(image.jpg) without using the actual filename of this image(image.jpg).

An example of what I mean, is like:

http://www.enom.com/domains/GifOutText.asp?t=X333030313734363E15203B3C333C30313B343830267B363A38

I know this is something different and it's in ASP, but just to give you an idea of what I mean.

Can anyone point me to such a script?
Thanks,
Michel,

Dan Grossman
09-11-2004, 12:50 PM
You can accomplish it in many ways depending on what you're really trying to do. A ForceType directive can parse /images/ as a PHP file then "images" can read the text that comes after that in the URI and parse it.

dutchee
09-11-2004, 01:14 PM
hmm do you think this is also possible with using .htaccess?

Dan Grossman
09-11-2004, 01:17 PM
Yes.

.htaccess:

<files image>
ForceType application/x-httpd-php
</files>


Those 3 lines in a .htaccess file in the folder with the file "images" would tell it to parse "images" as a PHP file even though it doesn't have an extension.

Then you can use http://www.example.com/images/text

"images" can read the word "text" or any other string you put after it like this:


$page = explode("/",$_SERVER['PATH_INFO']);
$string = $page[1];

lwknet
09-11-2004, 09:07 PM
simply output
Content-type: image/jpeg

this is the trick

EXOWorks
09-12-2004, 01:01 AM
In a php file use :
header( "Content-type: image/jpeg" );

"Content-type: image/jpeg" should change for a gif file, it will be "Content-type: image/gif" for a gif file..

You will need to determine the file type first and then generate a valid header and then output the file using readfile() function..

OR there is another simple way ... use include() function..