diff --git a/app/Http/Controllers/Userarea/UploadPhotosMobileController.php b/app/Http/Controllers/Userarea/UploadPhotosMobileController.php new file mode 100644 index 0000000..ecbc7d7 --- /dev/null +++ b/app/Http/Controllers/Userarea/UploadPhotosMobileController.php @@ -0,0 +1,74 @@ +query('iddatadb'); + + if (empty($iddatadb)) { + return response('ID riga non fornito', 400); + } + + // Show the upload form + return view('userarea.upload_photos_mobile', [ + 'iddatadb' => $iddatadb + ]); + } + + public function upload(Request $request) + { + // Validation + $request->validate([ + 'photo' => 'required|file|mimes:jpeg,png,gif,heic,heif|max:5120', // 5MB + 'iddatadb' => 'required|integer' + ]); + + $iddatadb = $request->input('iddatadb'); + $photo = $request->file('photo'); + $iduserlogin = auth()->id(); // assuming Laravel authentication + + // Check if user exists + $userExists = DB::table('auth_users')->where('id', $iduserlogin)->exists(); + if (!$userExists) { + return response()->json(['success' => false, 'message' => 'Utente non valido']); + } + + // Upload folder + $uploadDir = public_path('photostrf'); + if (!is_dir($uploadDir)) { + mkdir($uploadDir, 0755, true); + } + if (!is_writable($uploadDir)) { + return response()->json(['success' => false, 'message' => 'La cartella photostrf non รจ scrivibile']); + } + + // New filename + $timestamp = now()->format('YmdHis'); + $originalName = pathinfo($photo->getClientOriginalName(), PATHINFO_FILENAME); + $extension = strtolower($photo->getClientOriginalExtension()); + + $newFileName = "{$iddatadb}-{$timestamp}-{$originalName}.{$extension}"; + $destination = $uploadDir . '/' . $newFileName; + + // Move uploaded file + $photo->move($uploadDir, $newFileName); + + // Save DB record + DB::table('datadb_photos')->insert([ + 'iddatadb' => $iddatadb, + 'file_path' => $newFileName, + 'file_name' => $newFileName, + 'uploaded_by' => $iduserlogin + ]); + + return response()->json(['success' => true, 'message' => 'Foto caricata con successo']); + } +} diff --git a/public/userarea/load_photo.php b/public/userarea/load_photo.php index 34ca8e2..f3ac03b 100644 --- a/public/userarea/load_photo.php +++ b/public/userarea/load_photo.php @@ -14,13 +14,18 @@ if (!$iddatadb) { } try { - $stmt = $pdo->prepare("SELECT file_path FROM datadb_photos WHERE iddatadb = :iddatadb LIMIT 1"); + // Adjust the query to select all photo paths for the given iddatadb + $stmt = $pdo->prepare("SELECT file_path FROM datadb_photos WHERE iddatadb = :iddatadb"); $stmt->execute([':iddatadb' => $iddatadb]); - $photo = $stmt->fetch(PDO::FETCH_ASSOC); + $photos = $stmt->fetchAll(PDO::FETCH_ASSOC); - if ($photo && $photo['file_path']) { - $fullPath = '../photostrf/' . $photo['file_path']; // Assumi che le foto siano nella cartella photostrf - echo json_encode(['success' => true, 'file_path' => $fullPath]); + if ($photos && count($photos) > 0) { + // Prepare an array of full file paths + $photoPaths = array_map(function($photo) { + return '../photostrf/' . $photo['file_path']; // Assuming the photos are stored in the "photostrf" folder + }, $photos); + + echo json_encode(['success' => true, 'photos' => $photoPaths]); // Return an array of photo paths } else { echo json_encode(['success' => false, 'message' => 'Nessuna foto trovata']); } diff --git a/public/userarea/modal_parts.php b/public/userarea/modal_parts.php index b1e00cd..a3d7eba 100644 --- a/public/userarea/modal_parts.php +++ b/public/userarea/modal_parts.php @@ -13,29 +13,32 @@
| Num. Parte | -Descrizione Parte | -Azioni | -
|---|---|---|
| Num. Parte | +Descrizione Parte | +Azioni | +
| - | - | - - - - - - | -
| + | + | + + + + + + | +