Maruf Ahmed
Maruf Ahmed

Reputation: 115

Image Validation

I'm new in PHP and I'm trying to make an image validation with TYPE and SIZE but I've failed. Can anyone please help me ?

Here is my code:

if($fileName)
    {
        $filePath="images/admin/".$fileName;
        if(file_exists($filePath))
        {
            $a=gmdate("Yzhis");
            move_uploaded_file($_FILES["image"]["tmp_name"], "images/admin/".$a.$_FILES["image"]["name"]);
            $fileName=$a.$_FILES["image"]["name"];

        }
        else
        {
            move_uploaded_file($_FILES["image"]["tmp_name"], "images/admin/".$_FILES["image"]["name"]);

        }
    }

This code is uploading the files fine, but it's not doing the validation.

Thanks.

Upvotes: 0

Views: 179

Answers (3)

Avin Varghese
Avin Varghese

Reputation: 4370

You can use both of this function.

filesize ()

http://php.net/manual/en/function.filesize.php

getimagesize ()

http://php.net/manual/en/function.getimagesize.php

Get a complete list of GD and Image functions. http://www.php.net/manual/en/ref.image.php

Upvotes: 1

Álvaro González
Álvaro González

Reputation: 146630

Image validation can get as complex as you want, but the simplest way is good old getimagesize() function. Test its output against false and you're done.

Upvotes: 1

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181460

You can use "gd" or a similar library to validate and manipulate images in PHP.

Upvotes: 0

Related Questions