Fix per evitare eliminazione dell'intera cartella quando filename è vuoto
This commit is contained in:
parent
1ed6673ebd
commit
7a42b81a97
|
@ -250,36 +250,37 @@ class Uploads
|
|||
*/
|
||||
public static function delete($filename, $data)
|
||||
{
|
||||
$database = database();
|
||||
if (!empty($filename)){
|
||||
$database = database();
|
||||
|
||||
$name = $database->selectOne('zz_files', ['name'], [
|
||||
'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'],
|
||||
$name = $database->selectOne('zz_files', ['name'], [
|
||||
'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'];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue