i have a list of array that needs to be insert to database, can you help me how? its a list of exif data from image folder named uploads, every array consist selected exif to be stored
this is the array
Array
(
[0] => Array
(
[FileName] => foto1.jpg
[Model] => SM-A528B
[Longitude] => 106.79185497222
[Latitude] => -6.168561
)
[1] => Array
(
[FileName] => foto2.jpg
[Model] => SM-A528B
[Longitude] => 106.79185497222
[Latitude] => -6.168561
)
)
this is the code
$dir = 'uploads/';
$files = scandir($dir);
$ext_list = ['jpg','gif','png','heic','JPG','PNG','JPEG','GIF'];
foreach($files as $image_file)
{
$l = strtolower($image_file);
$parse_file_name = explode(".",$l);
$file_ext = end($parse_file_name);
if(in_array($file_ext,$ext_list))
{
$exif_data = exif_read_data($dir.$image_file);
$lon = getGps($exif_data["GPSLongitude"], $exif_data['GPSLongitudeRef']);
$lat = getGps($exif_data["GPSLatitude"], $exif_data['GPSLatitudeRef']);
$photos[] = [
'FileName'=>$exif_data['FileName'],
'Model'=>$exif_data['Model'],
'Longitude'=>$lon,
'Latitude'=>$lat,
];
$insert = $db->query("INSERT INTO exif_foto (file_name, Model,Longitude,Latitude) VALUES ( , '$p_image')"); //I want to correct this, this is still wrong.
}
}
// $insertexif = INSERT INTO Destinasi('');
// mysqli_query($con,$insertexif);
print"<pre>";
print_r($photos);
print"<pre>";
Any suggestions how to do it?
>Solution :
Your Insert can be devided as follows :
$sql = sprintf("INSERT INTO exif_foto (file_name, Model, Longitude, Latitude) VALUES ('%s', '%s', '%s', '%s')", $exif_data['FileName'], $exif_data['Model'], $lon, $lat);
$insert = $db->query($sql);