From fe4c242f26678a630c01107e687d31925e09493f Mon Sep 17 00:00:00 2001 From: PanSzelescik Date: Thu, 13 Jan 2022 15:32:04 +0100 Subject: [PATCH 1/4] To jest niepotrzebne, skrypt jest w js/plants.js --- panel/fragments/plants.html | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/panel/fragments/plants.html b/panel/fragments/plants.html index 26ff3bb..d2fdf96 100644 --- a/panel/fragments/plants.html +++ b/panel/fragments/plants.html @@ -15,24 +15,9 @@

Plants Database

Zdjęcia - - - + - \ No newline at end of file + From 6bbe50516f0bcea748dae93aa2edef8a4d1f639d Mon Sep 17 00:00:00 2001 From: PanSzelescik Date: Thu, 13 Jan 2022 15:46:34 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Dodanie=20plik=C3=B3w=20do=20all.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/all.php | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/api/all.php b/api/all.php index 2ceec31..522b912 100644 --- a/api/all.php +++ b/api/all.php @@ -5,7 +5,17 @@ include('./database.php'); $sql = $db->prepare("SELECT * FROM `$tablename`"); $sql->execute(); -$plants = $sql->fetchAll(PDO::FETCH_ASSOC); +$plants = []; + +foreach ($sql->fetchAll(PDO::FETCH_ASSOC) as $plant) { + $uploaddir = '../files/' . $plant['id']; + + if (file_exists($uploaddir) && is_dir($uploaddir)) { + $plant['files'] = $files = array_map(fn($value) => $uploaddir . '/' . $value, array_values(array_diff(scandir($uploaddir), array('.', '..')))); + } + + $plants[] = $plant; +} echo json_encode([ 'error' => false, @@ -15,12 +25,19 @@ ]); /* Struktura: -[ - { - "name": "", - "description": "", - "file": "http://...", <-- image - }, - ... -] -*/ \ No newline at end of file +{ + "error": false, + "status": 200, + "message": "Success", + "plants": [ + { + "id": 3, + "name": "", + "description": "", + "files": [ + "" + ] + } + ] +} +*/ From b4a9f6513e12795bcdc7dfaa5d2038b146f5efd7 Mon Sep 17 00:00:00 2001 From: PanSzelescik Date: Thu, 13 Jan 2022 15:49:06 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Nie=20wyrzucaj=20b=C5=82=C4=99du=20je=C5=9B?= =?UTF-8?q?li=20nie=20ma=20zdj=C4=99=C4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/info.php | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/api/info.php b/api/info.php index d95f97a..415a2c8 100644 --- a/api/info.php +++ b/api/info.php @@ -17,34 +17,13 @@ // FILES +$files = []; $uploaddir = '../files/' . $id; -if (!file_exists($uploaddir)) { - http_response_code(404); - echo json_encode([ - 'error' => true, - 'status' => 404, - 'id' => $id, - 'message' => "Can't find directory", - 'dir' => $uploaddir - ]); - die(); -} - -if (!is_dir($uploaddir)) { - http_response_code(500); - echo json_encode([ - 'error' => true, - 'status' => 500, - 'id' => $id, - 'message' => "Path is not directory", - 'dir' => $uploaddir - ]); - die(); +if (file_exists($uploaddir) && is_dir($uploaddir)) { + $files = array_map(fn($value) => $uploaddir . '/' . $value, array_values(array_diff(scandir($uploaddir), array('.', '..')))); } -$files = array_map(fn($value) => $uploaddir . '/' . $value, array_values(array_diff(scandir($uploaddir), array('.', '..')))); - // DATA FROM DB include('./database.php'); @@ -74,4 +53,4 @@ 'message' => 'Success', 'files' => $files, 'plant' => $plant -]); \ No newline at end of file +]); From 88905f2dc5e24480aa21e75e38354f0bbec85a97 Mon Sep 17 00:00:00 2001 From: PanSzelescik Date: Thu, 13 Jan 2022 15:52:12 +0100 Subject: [PATCH 4/4] Struktura --- api/add.php | 2 +- api/info.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/api/add.php b/api/add.php index b27c03c..6962f26 100644 --- a/api/add.php +++ b/api/add.php @@ -78,4 +78,4 @@ function generateRandomString($length = 10) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; -} \ No newline at end of file +} diff --git a/api/info.php b/api/info.php index 415a2c8..c9294ef 100644 --- a/api/info.php +++ b/api/info.php @@ -54,3 +54,20 @@ 'files' => $files, 'plant' => $plant ]); + +/* +{ + "error": false, + "status": 200, + "id": "", + "message": "Success", + "files": [ + "" + ], + "plant": { + "id": 3, + "name": "", + "description": "" + } +} +*/