php - How can I rename and set image acceptable format and size before uploading

I want to upload image to server directorate but for then I want to first of all check whether the image is a JPEG, GIF, PNG and also check whether the image file size is less than 15kb before renaming and uploading it to both database and server director. How can I do that using this my already written code here:
<?php
//instatiating our database objects
$db = new Pdoconn;
if(isset($_POST['submit'])){
//Collect Raw Data for Cleaning
$raw_firstName = cleandata($_POST['fname']);
$raw_lastName = cleandata($_POST['lname']);
$raw_username = cleandata($_POST['usern']);
$raw_email = cleandata($_POST['email']);
$raw_pass = cleandata($_POST['password']);
$raw_phone = cleandata($_POST['phone']);
$raw_dateJoin = cleandata($_POST['jdate']);
$raw_role = cleandata($_POST['role']);
$raw_employId = cleandata($_POST['employeeid']);
//Sanitize the Cleaned Date
$c_fname = sanitizeValue($raw_firstName);
$c_lname = sanitizeValue($raw_lastName);
$c_username = sanitizeValue($raw_username);
$c_email = validatemail($raw_email);
$c_password = sanitizeValue($raw_pass);
$c_phone = valint($raw_phone);
$c_jdate = sanitizeValue($raw_dateJoin);
$c_role = sanitizeValue($raw_role);
$c_employId = sanitizeValue($raw_employId);
$DateReg = date('Y-m-d');
//Hash Password
$Hashed_Pass = hashpassword($c_password);
//Collect Image
$c_img = $_FILES['image']['name'];
$c_img_tmp = $_FILES['image']['tmp_name'];
//move image to permanent location
move_uploaded_file($c_img_tmp, "assets/img/$c_img");
$db->query('SELECT * FROM employees WHERE username=:username');
//Bind Email Value
$db->bindValue(':username', $c_username, PDO::PARAM_STR);
//fetch Row
$row = $db->fetchSingle();
//check role
if($row){
echo '<div class="alert alert-danger text-center">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Sorry!</strong> Staff with Username: <span class="text-danger">' . $c_username . '</span> already Exist. Register or Try Again
</div>';
}else{
//Query to Insert/Add Employees in employees Table
$db->query("INSERT INTO employees(id, firstName, lastName, username, email, password, employeeId, joiningDate, phone, role, staffImage, dateAdded)VALUES(NULL, :fname, :lname, :username, :email, :password, :employeeId, :joiningDate, :phone, :role, :image, :dateAdded)");
//Bind Values to Query Parameters
$db->bindValue(':fname', $c_fname, PDO::PARAM_STR);
$db->bindValue(':lname', $c_lname, PDO::PARAM_STR);
$db->bindValue(':username', $c_username, PDO::PARAM_STR);
$db->bindValue(':email', $c_email, PDO::PARAM_STR);
$db->bindValue(':password', $Hashed_Pass, PDO::PARAM_STR);
$db->bindValue(':employeeId', $c_employId, PDO::PARAM_STR);
$db->bindValue(':joiningDate', $c_jdate, PDO::PARAM_STR);
$db->bindValue(':phone', $c_phone, PDO::PARAM_INT);
$db->bindValue(':role', $c_role, PDO::PARAM_STR);
$db->bindValue(':image', $c_img, PDO::PARAM_STR);
$db->bindValue(':dateAdded', $DateReg, PDO::PARAM_STR);
//Query to Check whether Staff Already Exist using Email
//Run Query
$run_employee = $db->execute();
if($run_employee){
redirect('employees.php');
keepmsg('<div class="alert alert-success text-center">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Success!</strong> Staff with Username : <span class="text-danger">' . $c_username . '</span> Registered successfully.
</div>');
}else{
echo '<script language="javascript">';
echo 'alert("Employee Could NOT be Registered!")';
echo '</script>';
}
}
}
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: gd library extension not available with this php installation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.