Page 1 of 1

Image script needs to be case sensitive and other things.

Posted: Wed Apr 22, 2009 10:08 pm
by Weston
Hello,

I have a very basic php script that displays images for me from behind the webroot so that the images are not in the web root folders to try to prevent people leaching them.

However my php script is very very basic and Im wondering if someone can help me out. The current problem that I have is that it's case sensitive dependant on the image name, but I'd like it to be non case sensitive. Images are usually brought in popup windows with simply
http://www.domain.com/image_now.php?file=ImageName.jpg But I'd like to make it so that that it can be called like that or called like
http://www.domain.com/image_now.php?file=ImAgENAmE.jPg and still bring back the image in the folder.

Details: Not necessary to read, just here in case someone is wondering why I need it to do this... I use a dynamic database system that allows users to enter a name of an item (any one of 10,690 items) and we have an image stored on the server for each item they can list. Regardless that we tell people to make sure they have the name of the item case sensitive, there are many people that don't get it, or don't want to get it, and will just write the name all in lower case, thus when someone clicks on the name of the item in this persons database listing, it simply doesn't show the image because it's not written exactly as the image name is on the server.

Would that be something simple to add into this script, and if so could someone give me a hand with it please.

I'd sure appreciate it if someone could help me out with this.

Script:

Code: Select all

<?php
 
    $file = $_GET['file'];
    $fileDir = '/home/path/user/images/';
 
    if (file_exists($fileDir . $file))
    {
        // Note: You should probably do some more checks 
        // on the filetype, size, etc.
        $contents = file_get_contents($fileDir . $file);
 
        // Note: You should probably implement some kind 
        // of check on filetype
        header('Content-type: image/jpeg');
 
        echo $contents;
    }
 
?>
I'd also like to make it so that if the script is called from anybody elses domain/website then it doesn't display the image for them so they can't just call the script from their own webpage and leech the images from my server.

Thanks again.

Re: Image script needs to be case sensitive and other things.

Posted: Wed Apr 22, 2009 10:33 pm
by reinerlee
I will suggest you strtolower all the image name in the uploading progress..

Then in your image_now.php reads strtolower($filename).

will that helps?