2018-10-16 16:28:42 +00:00
< ? php
defined ( 'BASEPATH' ) OR exit ( 'No direct script access allowed' );
2018-12-26 17:19:28 +00:00
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 ()
{
2018-12-26 17:19:28 +00:00
$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' ];
2018-12-26 17:19:28 +00:00
$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 () {
2018-12-26 17:19:28 +00:00
$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 " );
2018-12-26 17:19:28 +00:00
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
]);
}
}