sample upload compress my sqli



<?php
include("dbConfig.php");
 

if (isset($_POST['Submit'])) {
   

            // Getting file name
            $chat_img = $_FILES['image1']['name'];
       
            // Valid extension
            $valid_ext = array('png','jpeg','jpg');

            // Location
            $name = "upload/".$chat_img;

            // file extension
            $file_extension = pathinfo($name, PATHINFO_EXTENSION);
            $file_extension = strtolower($file_extension);

            // Check extension
            if(in_array($file_extension,$valid_ext)){ 

                // Compress Image
                compressImage($_FILES['image1']['tmp_name'],$name,60);

            }else{
                echo "Invalid file type.";
            }
        }
     // Compress image
        function compressImage($source, $destination, $quality) {

            $info = getimagesize($source);

            if ($info['mime'] == 'image/jpeg')
                $image = imagecreatefromjpeg($source);

            elseif ($info['mime'] == 'image/gif')
                $image = imagecreatefromgif($source);

            elseif ($info['mime'] == 'image/png')
                $image = imagecreatefrompng($source);

            imagejpeg($image, $destination, $quality);
}
       ?>
   <?php

$chat_user=$_POST['chat_user'];
$chat_msg=$_POST['chat_msg'];



mysqli_query($conn,"INSERT INTO chat_test (chat_user, chat_msg, chat_img)

VALUES ('$chat_user', '$chat_msg', '$chat_img')");


header("location: chat.php");

 
?>



Comments