I've got a directory during my web application where I wish to keep all of the account pictures. Customers can upload all kinds of images (png, digital, presen). However, I would like the look Hyperlink to be friendly, eg. http://example.com/static/picture/300-username, in which the file is 300-username, however with no extension. I figured of getting rid of the extension once the user uploads, with a PHP controller, give a:

header('Content-Type: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png');

It has labored well. I'm wondering however, if you can do this by placing an .htaccess file within the picture directory, with a few kind of Header, that whatever file is read within this directory, displays as picture. Is possible?

Don’t take away the extension, just offer extensionless URIs like /static/picture/300-username. Adding a line for your .htaccess:

Options +MultiViews

Apache sets the right content type for you personally. Begin to see the documentation for Content Negotiation.

First the journey have to be physically existent, else I do not think Apache can perform anything for you personally.

However, here might be a workaround utilizing a RewriteRule, keep your extension (incidentally, I believe it's bad practice to get rid of extension of the file, especially when they're not plain text files), and pay a asked for file like 300-username to rewrite to 300-username.jpg.

You cannot specify multiple Content-Type like this.. You have to pass the right header for every image offered:

    $user = '300-username';
    $picture = 'http://example.com/static/picture/' . $user;
    $info = getimagesize($picture);
    $fp = fopen($picture, "rb");
    if ($info && $fp) {
        header("Content-type: {$info['mime']}");
    } else {
        // error

(Code modified from PHP's getimagesize() documentation.)