Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/application/controllers/admin/Files.php

75 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2018-10-16 16:28:42 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Files extends MY_Controller
2018-10-16 16:28:42 +00:00
{
public function __construct()
{
parent::__construct();
$this->load->model('FileModel', '', TRUE);
}
public function index()
{
$this->neededPermission('file.view');
2018-10-16 16:28:42 +00:00
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, false);
2018-10-16 16:28:42 +00:00
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() {
$this->neededPermission('file.delete');
2018-10-16 16:28:42 +00:00
$id = filter_input(INPUT_POST, "id");
$this->FileModel->delete($id);
}
public function uploadImage()
{
header("Content-Type: application/json");
if (!$this->hasPermission('file.uploadManual')) {
2018-10-16 16:28:42 +00:00
echo json_encode([
'success' => false,
'message' => '<b>Fehler beim Upload!</b> 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' => '<b>Fehler beim Upload!</b> 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' => '<b>Bild erfolgreich hochgeladen!</b>',
'url' => $fileUrl
]);
}
}