Löschen von downloadbaren Dateien eingebaut

This commit is contained in:
Matthias Grief
2024-12-08 16:43:51 +01:00
committed by Eric Blommel
parent 7c5dfdfa92
commit 5ca5899368

View File

@@ -187,10 +187,20 @@ class TopicData
*/
private function addDownload(string $name, string $tmp_name): bool
{
if(!move_uploaded_file($tmp_name, Config::getTopicDirectory($this->getSubjectId() , $this->getId()) . "downloads/" . $name)) {
$downloadDirectory = Config::getTopicDirectory($this->getSubjectId() , $this->getId()) . "downloads/";
if(!is_dir($downloadDirectory)) {
if(!mkdir($downloadDirectory)) {
return false;
}
}
if(!move_uploaded_file($tmp_name, $downloadDirectory . $name)) {
return false;
}
$this->files[] = $name;
return true;
}
@@ -222,6 +232,21 @@ class TopicData
return true;
}
public function deleteDownload(string $name): bool
{
if(!isset($this->files[$name])) {
return false;
}
if(!unlink(Config::getTopicDirectory($this->getSubjectId() , $this->getId()) . "downloads/$name")) {
return false;
}
$this->files = array_diff($this->files, [$name]);
return true;
}
/**
* Löscht das Thema inklusive aller zugehörigen Dateien
* @return bool true, wenn erfolgreich gelöscht, sonst false