Upload und Entfernen von Bildern eingebaut
This commit is contained in:
committed by
Eric Blommel
parent
5ca5899368
commit
ad09024f48
@@ -181,11 +181,11 @@ class TopicData
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param string $name Dateiname von User, z.B. $_FILES['html-input-name']['name'][0]
|
||||
* @param string $tmp_name Temporärer Pfad zur hochgeladenen Datei, z.B. $_FILES['html-input-name']['tmp_name'][0]
|
||||
* @return bool true, wenn erfolgreich, sonst false
|
||||
*/
|
||||
private function addDownload(string $name, string $tmp_name): bool
|
||||
public function addDownload(string $name, string $tmp_name): bool
|
||||
{
|
||||
$downloadDirectory = Config::getTopicDirectory($this->getSubjectId() , $this->getId()) . "downloads/";
|
||||
|
||||
@@ -205,33 +205,10 @@ class TopicData
|
||||
}
|
||||
|
||||
/**
|
||||
* 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']
|
||||
* Löscht eine downloadbare Datei des Themas
|
||||
* @param string $name Dateiname
|
||||
* @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;
|
||||
}
|
||||
|
||||
public function deleteDownload(string $name): bool
|
||||
{
|
||||
if(!isset($this->files[$name])) {
|
||||
@@ -247,6 +224,43 @@ class TopicData
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt eine Datei als Bild zum Thema hoch
|
||||
* @param string $name Dateiname von User, z.B. $_FILES['html-input-name']['name'][0]
|
||||
* @param string $tmp_name Temporärer Pfad zum hochgeladenen Bild, z.B. $_FILES['html-input-name']['tmp_name'][0]
|
||||
* @return bool true, wenn erfolgreich, sonst false
|
||||
*/
|
||||
public function addImage(string $name, string $tmp_name): bool
|
||||
{
|
||||
$imageDirectory = Config::getTopicDirectory($this->getSubjectId() , $this->getId()) . "";
|
||||
|
||||
if(!is_dir($imageDirectory)) {
|
||||
if(!mkdir($imageDirectory)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!move_uploaded_file($tmp_name, $imageDirectory . $name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht eine downloadbare Datei des Themas
|
||||
* @param string $name Dateiname
|
||||
* @return bool true, wenn erfolgreich, sonst false
|
||||
*/
|
||||
public function deleteImage(string $name): bool
|
||||
{
|
||||
if(!unlink(Config::getTopicDirectory($this->getSubjectId() , $this->getId()) . "$name")) {
|
||||
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