note 40040 added to function.imagejpeg
| From: | php at andy-pearce dot com | Date: | Thu, 19 Feb 2004 17:42:53 +0000 |
| Subject: | note 40040 added to function.imagejpeg | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65413@lists.php.net to get a copy of this message | ||
This might be too obvious, but perhaps worth pointing out. If you want to simply serve images
without altering them, it's presumably more efficient to use something like the following:
<?php
// Normally $filename would depend on $_GET, etc.
$filename = '/photoalbum/images/test.jpg';
header('Content-type: image/jpeg');
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($filename));
readfile($filename);
?>
That way you avoid the overhead of reading and parsing the image, you simply send it directly to the
browser.
This is particularly useful if you're using PHP to implement access controls, because it allows
you to redirect files from areas of the filesystem browsers can't normally access (although the
filename should always come from your script if possible, and not from a URL field, to prevent
subverting it with URLs such as image.php?../../../etc/passwd).
----
Manual Page -- http://www.php.net/manual/en/function.imagejpeg.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40040
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40040&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40040&report=yes
Search -- http://master.php.net/manage/user-notes.php