mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Add a image library in the croppie
This commit is contained in:
parent
21246af3ab
commit
1916ea3c04
8 changed files with 479 additions and 50 deletions
46
view/list-images.delete.json.php
Normal file
46
view/list-images.delete.json.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../videos/configuration.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
$response = ['error' => true];
|
||||
|
||||
if (!User::isLogged()) {
|
||||
$response['msg'] = 'Not logged in';
|
||||
die(json_encode($response));
|
||||
}
|
||||
|
||||
$userId = User::getId();
|
||||
$relativeDir = "videos/userPhoto/Live/user_{$userId}/";
|
||||
$absoluteDir = realpath(__DIR__ . "/../{$relativeDir}");
|
||||
|
||||
if (!is_dir($absoluteDir)) {
|
||||
$response['msg'] = 'Directory not found';
|
||||
die(json_encode($response));
|
||||
}
|
||||
|
||||
$filename = basename($_POST['filename'] ?? '');
|
||||
|
||||
$files = scandir($absoluteDir);
|
||||
if (!in_array($filename, $files)) {
|
||||
forbiddenPage('Invalid filename');
|
||||
}
|
||||
|
||||
$fullPath = realpath("{$absoluteDir}/{$filename}");
|
||||
|
||||
if (!$fullPath || strpos($fullPath, $absoluteDir) !== 0 || !file_exists($fullPath)) {
|
||||
$response['msg'] = 'Invalid file';
|
||||
die(json_encode($response));
|
||||
}
|
||||
|
||||
if (unlink($fullPath)) {
|
||||
$jsonPath = preg_replace('/\.(jpg|jpeg|png|gif|webp)$/i', '.json', $fullPath);
|
||||
if (file_exists($jsonPath)) {
|
||||
unlink($jsonPath);
|
||||
}
|
||||
$response['error'] = false;
|
||||
$response['msg'] = 'File deleted';
|
||||
} else {
|
||||
$response['msg'] = 'Failed to delete file';
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
Loading…
Add table
Add a link
Reference in a new issue