<?php

include_once './db_functions.php'; 
$db = new DB_Functions(); 

$json = $_POST["ImageUpload"];

function filesize_dir($file) {
        exec('dir ' . $file, $inf);
        $size_raw = $inf[6];
        $size_exp = explode(" ",$size_raw);
        $size_ext = $size_exp[19];
        $size_int = (float) str_replace(chr(255), '', $size_ext);
        return $size_int;
    }

if (get_magic_quotes_gpc()){ 
		$json = stripslashes($json); 
	}

//Decode JSON into an Array 
$data = json_decode($json);

//$ei = $_REQUEST[eid];

$temp=0;
$a=array();

//$sel=mysql_fetch_array(mysql_query("SELECT engg_assign, job_no FROM complaints_master where job_no='$job_no'"));

for($i=0; $i<count($data) ; $i++) {
	$id=$data[$i]->_id;
    $b=array();
//$sel = $db->checkJobs($ei,$data[$i]->job_no);

	$b["id"] = $id;          
	$b["status"] = 'yes'; 
	$temp++; // get  no of jobs for which images are uploaded 
    $base=$data[$i]->encodedString;
	

	//$result = mysql_query("update complaints_master set img_path='$base' where job_no='MJ003'")or die(mysql_error());
   

 // Get file name posted from Android App
    $filename = $data[$i]->fileName;
	


    // Decode Image
  	 //if($base!=null){
    	   $binary=base64_decode($base);
		   $result = file_put_contents("taskImages/".$filename,$binary);
if($result=== FALSE) 
  die("Error writing data into $filename");
else
  echo "$result bytes written to $filename";
		   //}
  	  //else
    	//    {
   	 //$binary=null;
   	   //  }

    
 		
    // header('Content-Type: bitmap; charset=utf-8');
	/*$file_nm='billimage/'.$filename;
	
$gfz =  filesize_dir($binary); 
echo "Filesize is ".$gfz;
    // Images will be saved under 'www/imgupload/uplodedimages' folder
    
	$file = fopen($file_nm, 'w');	

	
    // Create File
	//if($binary!=null){
		
       fwrite($file, $binary);
		//}
	fclose($file);
*/	

	

array_push($a,$b); 
}
  
 json_encode($a); 

?>

