This is my action page and how i upload to a folder and save it in database.
<?php
session_start();
//Checking User Logged or Not
if(empty($_SESSION['user'])){
header('location:/VMS/login.php');
}
$host="127.0.0.1";
$username="root";
$pass="";
$db="VMS";
$conn=mysqli_connect($host,$username,$pass,$db);
if(!$conn){
die("Database connection error");
}
// insert query for register page
if(isset($_POST['ronel'])){
// $image = $_FILES['name']['name'];
//$target_dir = "uploads/";
//$target_file = $target_dir . basename($_FILES["name"]["name"]);
// Select file type
//$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
//$extensions_arr = array("jpg","jpeg","png","gif","pdf");
// Check extension
//if( in_array($imageFileType,$extensions_arr))
$mobile=$_POST['mobile'];
$email=$_POST['email'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$purpose=$_POST['purpose'];
$passtype=$_POST['passtype'];
$company=$_POST['company'];
$validupto=$_POST['validupto'];
$doctype=$_POST['doctype'];
$docnumber=$_POST['docnumber'];
$address=$_POST['address'];
$whomtomeet=$_POST['whomtomeet'];
$designation=$_POST['designation'];
$gender=$_POST['gender'];
$image = $_POST['image'];
$imgsrc = "upload/";
$image_parts = explode(";base64,", $image);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$fileName = uniqid() . '.jpg';
$file = $imgsrc . $fileName;
file_put_contents($file, $image_base64);
print_r($fileName);
if($_POST['nationality'] === 'others'){
$nationality=$_POST['nationality'];
$country=$_POST['country'];
$passport=$_POST['passport'];
$validity=$_POST['validity'];
$query="INSERT INTO `visitors` (`mobile`,`email`,`firstname`,`lastname`,`purpose`,`passtype`,`company`,`validupto`,`time`,`date`,`doctype`,`docnumber`,`address`,`whomtomeet`,`designation`,`gender`,`nationality`,`country`,`passport`,`validity`,`image`) VALUES ('$mobile','$email','$firstname','$lastname','$purpose','$passtype','$company','$validupto',current_timestamp(),current_timestamp(),'$doctype','$docnumber','$address','$whomtomeet','$designation','$gender','$nationality','$country','$passport','$validity','$image')";
$res=mysqli_query($conn,$query);
if($res){
$_SESSION['success']="Not Inserted successfully!";
header('Location:');
}else{
echo "<script>alert('Data not inserted! Kindly contact ITSUPPORT OTPC');</script>";
}
// Upload file
// move_uploaded_file($_FILES['name']['tmp_name'],$target_dir.$image);
}
else {