Пример #1
0
 /**
  * Upload a new file.
  *
  * @param String $folder_id Directory entry id of the folder to upload to
  */
 public function upload_action($folder_id, $page = 1)
 {
     if (!$this->full_access) {
         throw new AccessDeniedException();
     }
     PageLayout::setTitle(_('Datei hochladen'));
     $folder_id = $folder_id ?: $this->context_id;
     if ($folder_id === $this->context_id) {
         $directory = new RootDirectory($this->context_id);
     } else {
         $dirEntry = new DirectoryEntry($folder_id);
         $directory = $dirEntry->file;
     }
     $directory->checkAccess();
     if (Request::isPost()) {
         $title = Request::get('title');
         $description = Request::get('description', '');
         $restricted = Request::int('restricted', 0);
         $count = count($_FILES['file']['name']);
         $failed = array();
         for ($i = 0; $i < $count; $i++) {
             if ($_FILES['file']['error'][$i] !== 0) {
                 $failed[] = array($_FILES['file']['name'][$i], 'remote');
                 continue;
             }
             $filename = $_FILES['file']['name'][$i];
             $filesize = $_FILES['file']['size'][$i];
             $mimetype = $_FILES['file']['type'][$i];
             $tempname = $_FILES['file']['tmp_name'][$i];
             $fileExtension = explode('.', $filename);
             if (!empty($fileExtension) && !empty($this->userConfig['types'])) {
                 foreach ($this->userConfig['types'] as $typ) {
                     if ($typ['type'] == $fileExtension[count($fileExtension) - 1]) {
                         $failed[] = array($_FILES['file']['name'][$i], 'forbidden_type');
                     }
                 }
             }
             $restQuota = (int) $this->userConfig['quota'] - DiskFileStorage::getQuotaUsage($this->context_id);
             if ($filesize > $restQuota) {
                 $failed[] = array($_FILES['file']['name'][$i], 'quota');
             } else {
                 if ($filesize > (int) $this->userConfig['upload_quota']) {
                     $failed[] = array($_FILES['file']['name'][$i], 'upload_quota');
                 } else {
                     $filename = $directory->ensureUniqueFilename($filename);
                     $this_title = $title;
                     if ($this_title && $count > 1) {
                         $this_title .= ' ' . sprintf(_('(%u von %u)'), $i + 1, $count);
                     }
                     $new_file = $directory->createFile($filename, $description, $this->context_id);
                     $handle = $new_file->file;
                     $handle->restricted = $restricted;
                     $handle->mime_type = $mimetype;
                     $handle->size = $filesize;
                     try {
                         $handle->setContentFromFile($tempname);
                         $handle->update();
                     } catch (Exception $e) {
                         if (Studip\ENV === 'development') {
                             throw $e;
                         } else {
                             $failed[] = array($filename, 'local');
                             $handle->delete();
                         }
                     }
                 }
             }
         }
         if (!empty($failed)) {
             $remote = array_map('reset', array_filter($failed, function ($item) {
                 return $item[1] === 'remote';
             }));
             if (!empty($remote)) {
                 $message = MessageBox::error(_('Folgende Dateien wurden fehlerhaft hochgeladen:'), $remote);
                 PageLayout::postMessage($message);
             }
             $forbidden = array_map('reset', array_filter($failed, function ($item) {
                 return $item[1] === 'forbidden_type';
             }));
             if (!empty($forbidden)) {
                 $message = MessageBox::error(_('Der Upload folgender Dateien ist verboten:'), $forbidden);
                 PageLayout::postMessage($message);
             }
             $quota = array_map('reset', array_filter($failed, function ($item) {
                 return $item[1] === 'quota';
             }));
             if (!empty($quota)) {
                 $message = MessageBox::error(_('Für folgende Dateien ist der verbleibende Speicherplatz zu klein:'), $quota);
                 PageLayout::postMessage($message);
             }
             $upload = array_map('reset', array_filter($failed, function ($item) {
                 return $item[1] === 'upload_quota';
             }));
             if (!empty($upload)) {
                 $message = MessageBox::error(_('Folgende Dateien sind zu groß für den Upload:'), $upload);
                 PageLayout::postMessage($message);
             }
             $local = array_map('reset', array_filter($failed, function ($item) {
                 return $item[1] === 'local';
             }));
             if (!empty($local)) {
                 $message = MessageBox::error(_('Folgende Dateien konnten nicht gespeichert werden:'), $local);
                 PageLayout::postMessage($message);
             }
         }
         if ($count - count($failed) > 0) {
             Metrics::count('core.personal_files.uploads', $count - count($failed));
             $message = sprintf(_('%u Dateien wurden erfolgreich hochgeladen.'), $count - count($failed));
             PageLayout::postMessage(MessageBox::success($message));
         }
         $this->redirect('document/files/index/' . $folder_id . '/' . $page);
     }
     $this->folder_id = $folder_id;
     $this->page = $page;
     PageLayout::setTitle(_('Datei hochladen'));
 }
Пример #2
0
 /**
  * Downloads a bunch of files as a zip archive.
  *
  * @param Array  $files    Directory entries or files to download
  * @param String $filename Filename for the archive.
  */
 protected function download_files($files, $filename = 'Stud-IP.zip')
 {
     $files = (array) $files;
     $tmp_file = tempnam($GLOBALS['TMP_PATH'], 'doc');
     $zip = new ZipArchive();
     $open_result = $zip->open($tmp_file, ZipArchive::CREATE);
     if (true !== $open_result) {
         throw new Exception('Could not create zip file (' . $open_result . ')');
     }
     foreach ($files as $file) {
         $this->addToZip($zip, $file, '', $remove);
     }
     if (true !== ($close_result = $zip->close())) {
         throw new Exception('Could not close zip file (' . $close_result . ')');
     }
     array_map('unlink', $remove);
     Metrics::count('core.personal_files.downloads', count($files));
     // TODO: swap "Stud-IP.zip" with a more appropriate name
     $filename = basename($filename, '.zip') . '.zip';
     $this->initiateDownload(false, $filename, 'application/zip', filesize($tmp_file), fopen($tmp_file, 'r'));
     $this->download_remove = $tmp_file;
 }
Пример #3
0
    //wurde eine Datei hochgeladen/aktualisiert?
    $cmd = Request::get("cmd");
    if (($cmd=="upload") && (!Request::submitted("cancel")) && ($folder_system_data["upload"])) {
        if (!$folder_system_data["zipupload"]){
            Metrics::increment('core.file_upload');

            upload_item ($folder_system_data["upload"], TRUE, FALSE, $folder_system_data["refresh"]);
            $open = $dokument_id;
            $close = $folder_system_data["refresh"];
            $folder_system_data["upload"]='';
            $folder_system_data["refresh"]='';
        } elseif ($rechte && get_config('ZIP_UPLOAD_ENABLE')) {
            $uploaded_files = upload_zip_item();
            if ($uploaded_files !== false) {
                Metrics::count('core.file_upload', $uploaded_files);
            }
            $folder_system_data["upload"]='';
            $folder_system_data["zipupload"]='';
        }
        unset($cmd);
        }

    //wurde eine Datei verlinkt?
    if (($cmd=="link") && (!Request::submitted("cancel")) && ($folder_system_data["link"])) {
        if (link_item ($folder_system_data["link"], TRUE, FALSE, $folder_system_data["refresh"],FALSE)) {
            $open = $dokument_id;
            $close = $folder_system_data["refresh"];
            $folder_system_data["link"]='';
            $folder_system_data["refresh"]='';
            $folder_system_data["update_link"]='';