I have a website where users can upload images. And i have restricted file extensions for PNG, JPG, JPEG .
problem :
I have a zip file stored on my local computer folder. Zip file name = "lara.zip"
Later i changed this zip file name to "Lara.jpg"
and then i uploaded this zip with the extension of jpg to my website through this uploading script. The script successfully submitted my and it uploaded this file to my website.
Solution : ???????????????????????
Question : How can i prevent from users to upload extensions changed unwanted files ? How can i find the file they uploads are exactly an image ???
Thanks .
Now i have edited the question, But codes doesn't check for this error weather if its an confirmed extension or not.
 if (isset($_FILES["image_upload"]["name"])) {
        $name = $_FILES["image_upload"]["name"];
        $size = $_FILES["image_upload"]["size"];
        $ext = end(explode(".", $name));
        $allowed_ext = array("png", "jpg", "jpeg", "PNG", "JPG", "JPEG");
        $checkexactlyimage = getimagesize($name);
        $allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
        $detectedType = exif_imagetype($_FILES['image_upload']['tmp_name']);
        $detectedTypeerror = !in_array($detectedType, $allowedTypes);
        if ($detectedTypeerror !== false) {
            echo "Only JPG,PNG and JEPG files are allowed";
        } else if ($check !== false) {
            echo "Only JPG,PNG and JEPG files are allowed";
        } else if (in_array($ext, $allowed_ext)) {
            if ($size < (5000000)) {
                $new_image = '';
                $new_name = md5(rand()) . '.' . $ext;
                $path = '../folder/' . $new_name;
                list($width, $height) = getimagesize($_FILES["image_upload"]["tmp_name"]);
                if ($ext == 'png') {
                    $new_image = imagecreatefrompng($_FILES["image_upload"]["tmp_name"]);
                }
                if ($ext == 'jpg' || $ext == 'JPG' || $ext == 'JPEG' || $ext == 'jpeg') {
                    $new_image = imagecreatefromjpeg($_FILES["image_upload"]["tmp_name"]);
                }
                $new_width = 730;
                $new_height = ($height / $width) * 400;
                $tmp_image = imagecreatetruecolor($new_width, $new_height);
                imagecopyresampled($tmp_image, $new_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
                imagejpeg($tmp_image, $path, 100);
                imagedestroy($new_image);
                imagedestroy($tmp_image);
                // third get your image
                $image3 = $path;
                $picture3 = base64_encode(file_get_contents($image3));
                $adimageno = 'data:image/gif;base64,' . $picture3 . '"';
                echo '<img src="' . $adimageno . '"  width="300" class="_setup-width-345"/>';
                $ifexistalready = "query";
                $ifexistalreadyqry = mysql_query($ifexistalready);
                $existornot = mysql_fetch_assoc($ifexistalreadyqry);
                $getidofstore = $existornot['ID'];
                $getcvrimage = $existornot['Simage'];
                $updatetable = "query";
                $updatetableqry = mysql_query($updatetable);
                if ($updatetableqry) {
                    unlink('../store-image/' . $getcvrimage);
                } else {
                    echo "Error on uploading image";
                }
            } else {
                echo 'Image File size must be less than 5 MB';
            }
        } else {
            echo 'Only JPG,PNG and JEPG files are allowed';
        }
    } else {
        echo 'Please select a image file';
    }