Fix per evitare eliminazione dell'intera cartella quando filename è vuoto

This commit is contained in:
Luca 2020-06-25 12:53:12 +02:00
parent 1ed6673ebd
commit 7a42b81a97
1 changed files with 25 additions and 24 deletions

View File

@ -250,36 +250,37 @@ class Uploads
*/ */
public static function delete($filename, $data) public static function delete($filename, $data)
{ {
$database = database(); if (!empty($filename)){
$database = database();
$name = $database->selectOne('zz_files', ['name'], [ $name = $database->selectOne('zz_files', ['name'], [
'filename' => $filename, 'filename' => $filename,
'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null,
'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null,
'id_record' => $data['id_record'],
])['name'];
$fileinfo = self::fileInfo($filename);
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
$files = [
$directory.'/'.$fileinfo['basename'],
$directory.'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension'],
$directory.'/'.$fileinfo['filename'].'_thumb100.'.$fileinfo['extension'],
$directory.'/'.$fileinfo['filename'].'_thumb250.'.$fileinfo['extension'],
];
if (delete($files)) {
$database->delete('zz_files', [
'filename' => $fileinfo['basename'],
'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null, 'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null,
'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null, 'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null,
'id_record' => $data['id_record'], 'id_record' => $data['id_record'],
]); ])['name'];
return $name; $fileinfo = self::fileInfo($filename);
$directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']);
$files = [
$directory.'/'.$fileinfo['basename'],
$directory.'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension'],
$directory.'/'.$fileinfo['filename'].'_thumb100.'.$fileinfo['extension'],
$directory.'/'.$fileinfo['filename'].'_thumb250.'.$fileinfo['extension'],
];
if (delete($files)) {
$database->delete('zz_files', [
'filename' => $fileinfo['basename'],
'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null,
'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null,
'id_record' => $data['id_record'],
]);
return $name;
}
} }
return null; return null;
} }