<?php
 
include 'dbconfig.php';
 
// Create connection

 
$item_code=$_POST['itemcode'];
$namafile=$_POST['namafile'];
$image=$_POST['image'];
 

//echo $notrans;
 
$conn = mysqli_connect($servername, $username, $password, $dbname);
 
// Check connection
 
if (!$conn) {
 
    die("Connection failed: " . mysqli_connect_error());
 
}

 

$sql1=mysqli_query($conn,"insert into tbpict (item_code,name_file,path_file) values ('$item_code','$namafile','x')");
// $sql1=$conn->prepare("INSERT INTO tbpict (item_code,name_file,path_file) VALUES (?,?,?)");
// $sql1->bind_param("s",$item_code,$namafile,$namafile);
// $sql1->execute();

if(isset($_POST["image"])){
 
    $base64_string = $_POST["image"];  
   // $outputfile = "uploadpict/".$image.".jpg" ;
    $outputfile = "uploadpict/".$namafile.".jpg" ;
    $filehandler = fopen($outputfile, 'wb' ); 
    fwrite($filehandler, base64_decode($base64_string));
    fclose($filehandler); 
    $result['message']='Data input successfully';

} 
 

//$response = mysqli_query($conn, $query) or die('Error query:  '.$query);

$res=mysqli_query($conn,"select * from tbpict where item_code='$item_code'");

 if (mysqli_num_rows($res)>0)
  {
    $result['message']='ok';
  }
 
echo json_encode($result);
 
//$sql1->close(); 
mysqli_close($conn);

 
?>