Hinzufügen von downloadbaren Dateien eingebaut
This commit is contained in:
committed by
Eric Blommel
parent
0bde9b3d24
commit
7c5dfdfa92
@@ -179,6 +179,49 @@ class TopicData
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt eine Datei als Download zum Thema hoch
|
||||
* @param string $name Dateiname von User
|
||||
* @param string $tmp_name Temporärer Pfad zur hochgeladenen Datei
|
||||
* @return bool true, wenn erfolgreich, sonst false
|
||||
*/
|
||||
private function addDownload(string $name, string $tmp_name): bool
|
||||
{
|
||||
if(!move_uploaded_file($tmp_name, Config::getTopicDirectory($this->getSubjectId() , $this->getId()) . "downloads/" . $name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt eine oder mehrere Dateien als Downloads zu diesem Thema hoch
|
||||
* @param array $files Das array mit den Dateidaten, normalerweise z.B. $_FILES['html-input-name']
|
||||
* @return bool true, wenn erfolgreich, sonst false
|
||||
*/
|
||||
public function addDownloads(array $files): bool
|
||||
{
|
||||
if(count($files) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!isset($files["name"]) || !isset($files["tmp_name"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!is_array($files["name"])) {
|
||||
return $this->addDownload($files["name"], $files["tmp_name"]);
|
||||
}
|
||||
|
||||
foreach ($files["name"] as $key => $name) {
|
||||
if(!$this->addDownload($name, $files["tmp_name"][$key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht das Thema inklusive aller zugehörigen Dateien
|
||||
* @return bool true, wenn erfolgreich gelöscht, sonst false
|
||||
|
||||
Reference in New Issue
Block a user