Re: .htaccess style rewrite with php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sjoerd

    Re: .htaccess style rewrite with php

    On 5 aug, 18:29, Joe <j...@faceh.com wrote:
    the issue with that is how to return image
    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) ;
    }
    }
    ?>
Working...