Voting

: six plus one?
(Example: nine)

The Note You're Voting On

therhinoman at hotmail dot com
18 years ago
If your upload script is meant only for uploading images, you can use the image function getimagesize() (does not require the GD image library) to make sure you're really getting an image and also filter image types.

<?php getimagesize($file); ?>

...will return false if the file is not an image or is not accessable, otherwise it will return an array...

<?php
$file
= 'somefile.jpg';

# assuming you've already taken some other
# preventive measures such as checking file
# extensions...

$result_array = getimagesize($file);

if (
$result_array !== false) {
   
$mime_type = $result_array['mime'];
    switch(
$mime_type) {
        case
"image/jpeg":
            echo
"file is jpeg type";
            break;
        case
"image/gif":
            echo
"file is gif type";
            break;
        default:
            echo
"file is an image, but not of gif or jpeg type";
    }
} else {
    echo
"file is not a valid image file";
}
?>

using this function along with others mentioned on this page, image ploading can be made pretty much fool-proof.

See http://php.net/manual/en/function.getimagesize.php for supported image types and more info.

<< Back to user notes page

To Top