Beispiel #1
0
 protected function importFiles($filename)
 {
     $tar = new Tar($filename);
     $files = 'files.tar';
     if ($tar->getIndexByFileName($files) === false) {
         throw new SystemException("Unable to find required file '" . $files . "' in the import archive");
     }
     $tar->extract($files, CMS_DIR . 'files/files.tar');
     $ftar = new Tar(CMS_DIR . 'files/files.tar');
     $contentList = $ftar->getContentList();
     foreach ($contentList as $key => $val) {
         if ($val['type'] == 'file' && $val['filename'] != '/files.tar' && $val['filename'] != 'files.tar') {
             $filename = preg_replace_callback('/([0-9]+)\\-/', function ($match) {
                 if (isset($match[1]) && isset($this->tmp['files'][$match[1]])) {
                     return $this->tmp['files'][$match[1]] . '-';
                 } else {
                     return $match[0];
                 }
             }, $val['filename']);
             $ftar->extract($key, CMS_DIR . 'files/' . $filename);
         } else {
             if (!file_exists(CMS_DIR . 'files/' . $val['filename'])) {
                 mkdir(CMS_DIR . 'files/' . $val['filename']);
             }
         }
     }
     $ftar->close();
     @unlink(CMS_DIR . 'files/files.tar');
     $tar->close();
     FileCacheBuilder::getInstance()->reset();
 }
Beispiel #2
0
 protected function init()
 {
     $this->filesToCategory = FileCacheBuilder::getInstance()->getData(array(), 'filesToCategory');
     $this->files = FileCacheBuilder::getInstance()->getData(array(), 'files');
 }
Beispiel #3
0
 /**
  * Handles upload of a file.
  */
 public function upload()
 {
     $files = $this->parameters['__files']->getFiles();
     $failedUploads = array();
     $result = array('files' => array(), 'errors' => array());
     foreach ($files as $file) {
         try {
             if ($file->getValidationErrorType()) {
                 $failedUploads[] = $file;
                 continue;
             }
             $data = array('title' => $file->getFilename(), 'filesize' => $file->getFilesize(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'uploadTime' => TIME_NOW);
             $uploadedFile = FileEditor::create($data);
             //clear cache
             FileCacheBuilder::getInstance()->reset();
             // create subdirectory if necessary
             $dir = dirname($uploadedFile->getLocation());
             if (!@file_exists($dir)) {
                 FileUtil::makePath($dir, 0777);
             }
             // move uploaded file
             if (@move_uploaded_file($file->getLocation(), $uploadedFile->getLocation())) {
                 @unlink($file->getLocation());
                 $result['files'][$file->getInternalFileID()] = array('fileID' => $uploadedFile->fileID, 'title' => $uploadedFile->getTitle(), 'filesize' => $uploadedFile->filesize, 'formattedFilesize' => FileUtil::formatFilesize($uploadedFile->filesize));
             } else {
                 // failure
                 $editor = new FileEditor($uploadedFile);
                 $editor->delete();
                 throw new UserInputException('file', 'uploadFailed');
             }
         } catch (UserInputException $e) {
             $file->setValidationErrorType($e->getType());
             $failedUploads[] = $file;
         }
     }
     // return results
     foreach ($failedUploads as $failedUpload) {
         $result['errors'][$failedUpload->getInternalFileID()] = array('title' => $failedUpload->getFilename(), 'filesize' => $failedUpload->getFilesize(), 'errorType' => $failedUpload->getValidationErrorType());
     }
     return $result;
 }