<?php
include ('dbConnect.php');

ini_set('post_max_size', '16M');
ini_set('upload_max_filesize', '16M');

foreach ($_FILES["images"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
		$bid=$_POST['bid'];
        $name = $_FILES["images"]["name"][$key];
		$filename = stripslashes($_FILES['images']['name'][$key]);
 	//get the extension of the file in a lower case format
  		$extension = getExtension($filename);
 		$extension = strtolower($extension);		
        $file_name=time().'.'.$extension;
		$success = move_uploaded_file( $_FILES["images"]["tmp_name"][$key], "../blog_images/" . $file_name);
		
		if($success){
				 $sql = "UPDATE `Blogs` SET `image` = '$file_name' WHERE `ID`= $bid";
				 $result=mysqli_query($hookup, $sql);
				if($result){				 
					echo "true";
				}else{
					echo "false";		
				}
		}else{			
			echo "<h4>There was a Problem Uploaded File</h4>";		
		}
		
    }
}

//Get the extension function	
function getExtension($str) {
	 $i = strrpos($str,".");
	 if (!$i) { return ""; }
	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}
?>