Move backend related code to new repository
This commit is contained in:
parent
a26dd9741a
commit
039c2948c4
6
.gitignore
vendored
6
.gitignore
vendored
@ -11,18 +11,12 @@
|
||||
# production
|
||||
/build
|
||||
|
||||
# images
|
||||
/img
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
php/composer*
|
||||
php/psalm.xml
|
||||
php/vendor
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
|
52
php/get.php
52
php/get.php
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
define("ROOT_URL", "http://localhost/react-photo-viewer/");
|
||||
define("RELATIVE_IMG", "../img/");
|
||||
define("ABSOLUTE_IMG", "img/");
|
||||
|
||||
main();
|
||||
|
||||
function main(): void {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$array = [];
|
||||
|
||||
$category = $data["category"];
|
||||
$directory = RELATIVE_IMG.$category;
|
||||
if (!is_dir($directory)) return;
|
||||
foreach (scandir($directory) as $file) {
|
||||
if ($file === ".") continue;
|
||||
if ($category === "" && $file === "..") continue;
|
||||
|
||||
if ($category != "") $file = $category.'/'.$file;
|
||||
$is_dir = is_dir(RELATIVE_IMG.$file);
|
||||
if (!$is_dir && !is_valid_file_type($file)) continue;
|
||||
|
||||
$file_item = [];
|
||||
$file_item["is_dir"] = $is_dir;
|
||||
$file_item["url"] = ROOT_URL.ABSOLUTE_IMG.$file;
|
||||
array_push($array, $file_item);
|
||||
}
|
||||
echo json_encode($array);
|
||||
}
|
||||
|
||||
function is_valid_file_type(string $filename): bool {
|
||||
$file_extensions = [
|
||||
// Image extensions
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'tiff',
|
||||
'bmp',
|
||||
'webp',
|
||||
'svg',
|
||||
// Video extensions
|
||||
'mp4',
|
||||
];
|
||||
|
||||
foreach ($file_extensions as $file_extension) {
|
||||
if (str_ends_with($filename, $file_extension)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user