note 65141 added to function.header
| From: | bradmatecpsdotcomdotau at osu1 dot php dot net | Date: | Tue, 25 Apr 2006 06:14:24 +0000 |
| Subject: | note 65141 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-109639@lists.php.net to get a copy of this message | ||
have not noticed or have missed one little simple trick i sort come across when looking at CGI.
basiclly a image serving script.
in your normal <img> tag you would put the src="" as
src="getimage.php?varImg=banner1"
------then in your getimage.php you would have ---------
<?php
$varImageType = substr($_REQUEST['varImg'], 0, 1);
$varImageName = substr($_REQUEST['varImg'], 1, strlen($_REQUEST['varImg']));
if ($varImageType=="1") {
$varFile = "http://www.imageplus.net.au/images/" .
$varImageName . ".jpg";
} elseif ($varImageType=="2") {
$varFile = "http://www.imageplus.net.au/images/" .
$varImageName . ".gif";
} elseif ($varImageType=="3") {
$varFile = "http://www.imageplus.net.au/images/" .
$varImageName . ".png";
} else {
// GERATE A IMAGE FOR NOT FOUND USING GD
}
$headers = apache_request_headers();
if (isset($headers['If-Modified-Since']) &&
(strtotime($headers['If-Modified-Since']) == filemtime($varFile))) {
header('Last-Modified: '.gmdate('D, d M Y H:i:s',
filemtime($varFile)).' GMT', true, 304);
} else {
// Image not cached or cache outdated, we respond '200 OK' and output the image.
header('Last-Modified: '.gmdate('D, d M Y H:i:s',
filemtime($varFile)).' GMT', true, 200);
header('Content-Length: '.filesize($varFile));
if ($varImageType=="1") {
header('Content-Type: image/jpeg');
} elseif ($varImageType=="2") {
header('Content-Type: image/gif');
} elseif ($varImageType=="3") {
header('Content-Type: image/png');
} else {
}
print file_get_contents($varFile);
}
?>
---------------------------------------------------------
Note that this above script is servers with a little more purpose, not written for speed. just for
easy to read.
in the src="" you'll notice the number 1 at the front of banner with the varImg=
variable.
providing you have the images folder set or you send the relative path for the image along with the
image name in the src="" then this should work fine.
The lower section of the code was from somewhere else here on php.net it just makes sure if the
image has been shown if it is cached. so loading time is quicker. but all of this can be controlled
with extra variables for the single function file.
This way you dont have to worry about headers and inserting code everywhere for a simple image. You
can proccess anything with the image and then show it with this method..
for another two lines of code you can make sure it shows images only for your domain/domains....
so on and so forth.
soon to be up and running properly, there will be such scripts n idea's avaliable at http://www.easyasweb.com
gotta love these post here ;)
----
Server IP: 203.220.0.234
Probable Submitter: 211.29.15.208
----
X-Spam-Status: No, hits=4.8 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_50_60,HTML_IMAGE_ONLY_12,HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- http://master.php.net/note/edit/65141
Del: integrated -- http://master.php.net/note/delete/65141/integrated
Del: useless -- http://master.php.net/note/delete/65141/useless
Del: bad code -- http://master.php.net/note/delete/65141/bad+code
Del: spam -- http://master.php.net/note/delete/65141/spam
Del: non-english -- http://master.php.net/note/delete/65141/non-english
Del: in docs -- http://master.php.net/note/delete/65141/in+docs
Del: other reasons-- http://master.php.net/note/delete/65141
Reject -- http://master.php.net/note/reject/65141
Search -- http://master.php.net/manage/user-notes.php