load->model('FileModel', '', TRUE); } public function index() { if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login')); if(isset($_FILES['fileUpload'])) { $fileName = $_FILES['fileUpload']['name']; $tmpName = $_FILES['fileUpload']['tmp_name']; $fileSize = $_FILES['fileUpload']['size']; $fileType = $_FILES['fileUpload']['type']; $this->FileModel->uploadFile($fileName, $tmpName, $fileSize, $fileType); unset($_FILES['fileUpload']); redirect(base_url('admin/files')); } $files = $this->FileModel->getFileList(); $this->load->view('admin/sidebar', ['title' => 'Alle Dateien', 'additionalStyles' => ['lib/jquery.fileupload.css', 'lib/jquery.fileupload-ui.css']]); $this->load->view('admin/files', ['files' => $files]); $this->load->view('admin/footer', ['additionalScripts' => ['lib/jquery.ui.widget.js', 'lib/jquery.iframe-transport.js', 'lib/jquery.fileupload.js', 'lib/jquery.fileupload-process.js', 'lib/jquery.fileupload-image.js', 'lib/jquery.fileupload-audio.js', 'lib/jquery.fileupload-video.js', 'lib/jquery.fileupload-validate.js', 'lib/jquery.fileupload-ui.js']]); } public function delete() { if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 9) redirect(base_url('login')); $id = filter_input(INPUT_POST, "id"); $this->FileModel->delete($id); } public function uploadImage() { header("Content-Type: application/json"); if (!isset($_SESSION['user']) || empty($_SESSION['user']) || $_SESSION['user']['rank'] < 6) { echo json_encode([ 'success' => false, 'message' => 'Fehler beim Upload! Aufgrund von zu geringen Zugriffsrechten konnte das Bild leider nicht hochgeladen werden. Sollte es sich dabei um ein Irrtum handeln, kontaktiere bitte einen Admin über das Kontaktformular.' ]); exit; } if(!isset($_POST['image']) || !isset($_POST['name']) || !isset($_POST['type']) || !isset($_POST['size'])) { echo json_encode([ 'success' => false, 'message' => 'Fehler beim Upload! Das hochgeladene Bild enthält fehlerhafte Informationen.' ]); exit; } $image = str_replace(' ', '+', $_POST['image']); $image = substr($image, strpos($image, ',') + 1); $image = base64_decode($image); $fileUrl = $this->FileModel->uploadFileByContent($image, $_POST['name'], $_POST['type'], $_POST['size']); echo json_encode([ 'success' => true, 'message' => 'Bild erfolgreich hochgeladen!', 'url' => $fileUrl ]); } }