On Aug 5, 8:28 pm, Sjoerd <sjoer...@gmail .comwrote:
That looks pretty promising, I'll give it a try, thanks!
On 5 aug, 18:29, Joe <j...@faceh.com wrote:
>
>
You have to provide some headers, like Content-Type, Content-Length,
Content-Disposition. Here's an example:
>
<?php
class FileServer {
function serve($path) {
$mime = self::getMimeTy pe($path);
$size = self::getFilesi ze($path);
header('Content-Type: '.$mime);
header('Content-Length: '.$size);
readfile($path) ;
}
>
function getMimeType($pa th) {
$extension = strtolower(subs tr(strrchr($pat h, "."),
1));
if ($extension == 'jpg') return 'image/jpeg';
if ($extension == 'jpeg') return 'image/jpeg';
if ($extension == 'png') return 'image/png';
return `file -bi $path`; // uses the 'file' command,
available on unix.
}
>
function getFilesize($pa th) {
return filesize($path) ;
}}
>
?>
>
the issue with that is how to return image
files, or pdf files, or .doc files, etc. as that file type.
files, or pdf files, or .doc files, etc. as that file type.
You have to provide some headers, like Content-Type, Content-Length,
Content-Disposition. Here's an example:
>
<?php
class FileServer {
function serve($path) {
$mime = self::getMimeTy pe($path);
$size = self::getFilesi ze($path);
header('Content-Type: '.$mime);
header('Content-Length: '.$size);
readfile($path) ;
}
>
function getMimeType($pa th) {
$extension = strtolower(subs tr(strrchr($pat h, "."),
1));
if ($extension == 'jpg') return 'image/jpeg';
if ($extension == 'jpeg') return 'image/jpeg';
if ($extension == 'png') return 'image/png';
return `file -bi $path`; // uses the 'file' command,
available on unix.
}
>
function getFilesize($pa th) {
return filesize($path) ;
}}
>
?>
Comment