<?php

$valid_extensions = array('jpeg', 'jpg', 'png', 'gif', 'bmp' , 'pdf' , 'doc' , 'ppt','xlsx','docx','xls'); // valid extensions
$path = dirname(__DIR__).'/liveclass/uplaods/'; // upload directory

if(!empty($_FILES['image']))
{

// folder path to delete all files
//$path = "./fpdf182/pdf_file";
 
// list of css file names located inside the folder
$files = glob($path.'*');
 
// delete all the files from the list 
foreach($files as $file){
 if(is_file($file)){
 unlink($file);
 }
}




$img = $_FILES['image']['name'];
$tmp = $_FILES['image']['tmp_name'];

// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));

// can upload same image using rand function
//$final_image = rand(1000,1000000).$img;
$final_image =str_replace(" ","_","$img");
//$final_image = $img;
// check's valid format
if(in_array($ext, $valid_extensions)) 
{ 
$path = $path.strtolower($final_image); 

if(move_uploaded_file($tmp,$path)) 
{
echo "<img id='img_view' src='$path' />";
//echo "$path";
//$name = $_POST['name'];
//$email = $_POST['email'];

//include database configuration file
//include_once 'db.php';

//insert form data in the database
//$insert = $db->query("INSERT uploading (name,email,file_name) VALUES ('".$name."','".$email."','".$path."')");

//echo $insert?'ok':'err';
//echo 'upload succesfully';

}
} 
else 
{
echo 'invalid';
}
}
?>