|
|
|
A simple example that allows images to be included in HTML without being in the web site's file path
I’ve looked in a pot-full of forums for the answer to this question:
How can I get the ‘src’ parameter of an HTML ‘img’ tag to refer to an image that is not in the web site’s path? I wanted to be able to do this so that images could be more secure and wouldn’t need to be replicated for multiple subdomains.
What I finally pieced together is very straightforward: the seeds of it were in several places, but here’s a working model all in one place.
(By the way, this has been tested with Fireefox, IE7, and Chrome. My web site runs under PHP 5 on an Apache server.)
I decided to keep my images in a folder called ‘help’ that is at a peer level with ‘public_html’. In ‘help’ I have another folder called ‘sample’
Here’s the original image tag: <img src=”sample/myPicutre.jpg”>
Here’s the modified tag: <img src=”index.php?helpimage=sample/myPicture.jpg">
Here’s how my modified index.php file looks
index.php
| <?php
extract($_GET); // will contain the ‘helpimage’ variable
if(isset($helpimage)) // if this is a call for an image
{
$f=pathinfo($helpimage); // and if its an actual image file (hacker-resistance)
if($f['extension']=="jpg")
{
chdir("../help"); // jump up one level to the help folder
readfile($helpimage); // and send the image back to the browser.
return; // that’s it
}
}
?> | |
… whatever else index.php is supposed to do
|
|
| How to preset a text string in a textarea input field Categories : HTML, HTML and PHP, PHP, Beginner Guides | | | Newbie Notes #1 - Making a form return to itself Categories : PHP, Beginner Guides, HTML and PHP | | | mySQL/PHP/search with multientry
form and table output with colored rows Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | Simple POST and GET example Categories : PHP, Beginner Guides, Form Processing, HTML and PHP | | | Newbie Notes #9 - Hyperlinking a post Categories : PHP, Java Script, HTML and PHP, Beginner Guides | | | Snipe.Net's Web Design Color Scheme Previewer- Allows uses to input hex
codes for their text, background, and link colors, and preview the color
scheme with their background image. Example:
http://www.snipe.net/tech/snipeschool/hex.php3 Categories : PHP, HTML and PHP, General, Graphics, HTML | | | Barcodes On The Fly With GD Categories : Ecommerce, Graphics, HTML and PHP, PHP | | | PHP based HTML rabbing Tools Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides | | | Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance. Categories : HTML, PHP, HTML and PHP, Beginner Guides | | | How to Create a Shoutbox Using PHP & MySQL Categories : PHP, MySQL, Web Applications, Beginner Guides, HTML and PHP | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | Kewl Date Example Categories : PHP, HTML and PHP, Date Time, CSS, Beginner Guides | | | Functions for loading images into a MySQL database and displaying them. Categories : Graphics, HTML and PHP, MySQL, PHP, Databases | | | How to display any array in several rows and columns of a table. Not just
in one column or in alternate rows. This example shows a nice color table
generated with PHP, but can be used with any array values(e.g. Database) Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics | |
|
|
|