Estoy intentando cargar las imágenes relacionadas con id del producto, pero no se como hacerlo con la librería https://innostudio.de/fileuploader/
He probado añadir el $appendedFiles
, pero me carga todas las imágenes que están en la carpeta images
Este es mi código
$id_product = id_product($_GET['id']); if(empty($id_product)){ header('Location: home.php'); } $product = get_product_per_id($connect, $id_product); if (!$product){ header('Location: ' . SITE_URL . '/controller/home.php'); } $product = $product['0']; } function galeria($connect){ if (isset($_GET['id']) && !empty($_GET['id'])) { $id = intval($_GET['id']); $sentence = $connect->prepare('SELECT * FROM galeria WHERE product_id = ?'); $sentence->execute([$id]); return $sentence->fetchAll(); }} // create an empty array // we will add to this array the files from directory below // here you can also add files from MySQL database $galeria = galeria($connect); $appendedFiles = array($galeria); // scan uploads directory $uploadsFiles = array_diff(scandir('../images/'), array('.', '..')); // add files to our array with // made to use the correct structure of a file foreach($uploadsFiles as $file) { // skip if directory if(is_dir($file)) continue; // add file to our array // !important please follow the structure below $appendedFiles[] = array( "name" => $file, "type" => FileUploader::mime_content_type('../images/' . $file), "size" => filesize('../images/' . $file), "file" => '../images/' . $file, "data" => array( "url" => 'http://localhost/fileuploader/examples/appended-files/uploads/' . $file ) ); } // convert our array into json string $appendedFiles = json_encode($appendedFiles);
El input
de las imágenes
<input type="file" name="files" data-fileuploader-files='<?php echo $appendedFiles;?>'>