acroporas Posted November 18, 2006 Share Posted November 18, 2006 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? Quote Link to comment Share on other sites More sharing options...
bqallover Posted November 18, 2006 Share Posted November 18, 2006 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. :) Quote Link to comment Share on other sites More sharing options...
acroporas Posted November 19, 2006 Author Share Posted November 19, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.