added feature to save image into database and after upload it can be chose by dropdown
This commit is contained in:
@@ -1,25 +1,53 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include('include/headscript.php');
|
||||
include('include/headscript.php'); // აქედან უნდა იყოს DB კავშირიც
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$dataURL = $_POST['dataURL'] ?? null;
|
||||
$filename = $_POST['filename'] ?? null;
|
||||
$dataURL = $_POST['dataURL'] ?? null;
|
||||
$filename = $_POST['filename'] ?? null;
|
||||
$iddatadb = $_POST['iddatadb'] ?? null; // 🟢 ახალი ველი
|
||||
|
||||
if (!$dataURL || !$filename) {
|
||||
if (!$dataURL || !$filename || !$iddatadb) {
|
||||
echo json_encode(['success' => false, 'message' => 'Dati mancanti']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// --- ფაილის შენახვა ---
|
||||
$data = explode(',', $dataURL)[1];
|
||||
$decodedData = base64_decode($data);
|
||||
$filePath = '../photostrf/annotated/' . $filename; // Crea una sottocartella 'annotated' per le foto modificate
|
||||
if (!file_exists('../photostrf/annotated')) {
|
||||
mkdir('../photostrf/annotated', 0777, true);
|
||||
|
||||
$dirPath = '../photostrf/annotated';
|
||||
if (!file_exists($dirPath)) {
|
||||
mkdir($dirPath, 0777, true);
|
||||
}
|
||||
|
||||
$filePath = $dirPath . '/' . $filename;
|
||||
file_put_contents($filePath, $decodedData);
|
||||
echo json_encode(['success' => true, 'file_path' => $filePath, 'message' => 'Foto salvata con successo']);
|
||||
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// --- ბაზაში ჩაწერა ---
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO datadb_photos (iddatadb, file_path, file_name, uploaded_at, uploaded_by)
|
||||
VALUES (:iddatadb, :file_path, :file_name, NOW(), :uploaded_by)
|
||||
");
|
||||
$stmt->execute([
|
||||
':iddatadb' => $iddatadb,
|
||||
':file_path' => $filePath,
|
||||
':file_name' => $filename,
|
||||
':uploaded_by'=> $iduserlogin
|
||||
]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'file_path' => $filePath,
|
||||
'message' => 'Foto salvata con successo e registrata nel DB'
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]);
|
||||
echo json_encode(['success' => false, 'message' => 'Errore: ' . $e->getMessage()]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user