RE: [PHP] Streaming a jpg
| From: | Don Read | Date: | Sat, 11 Aug 2001 04:21:47 +0000 |
| Subject: | RE: [PHP] Streaming a jpg | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-62245@lists.php.net to get a copy of this message | ||
On 10-Aug-2001 Todd Cary wrote:
> If I know the location and name of a jpeg file, can I stream it to a
> HTML page?
>
> What I have is a DB that contains the path and name of jpeg files.
> These files are "outside of the www Home directory" for security
> reasons. I would like to access the files from my PHP script and stream
> them to the page.
>
> Never having done any streaming (PHP files) with PHP, I am not sure if
> this can be done and if it can, how to do it.
>
<?php
//
// show.php?fname=da_image.jpg
//
$basedir='/usr/website/images/';
$mime_types = array(
'.asf' => 'application/vnd.ms-asf',
'.gif' => 'image/gif',
'.png' => 'image/png',
'.jpeg' => 'image/jpeg',
'.jpg' => 'image/jpeg',
'.mov' => 'video/quicktime',
'.mpe' => 'video/mpeg',
'.mpeg' => 'video/mpeg',
'.mpg' => 'video/mpeg'
);
$ext = strtolower(strrchr($fname,'.'));
$fullpath = $basedir .$fname;
if (! file_exists($fullpath)) {
exit(0);
}
header('Content-type: ' .$mime_types[$ext]);
header('Content-length: ' .filesize($fullpath));
@readfile($fullpath);
?>
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.