Exemplo n.º 1
0
 protected function _process()
 {
     $return = array();
     try {
         $fileInfo = reset($_FILES);
         if (empty($fileInfo)) {
             throw new CM_Exception('Invalid file upload');
         }
         if (isset($fileInfo['error']) && $fileInfo['error'] !== UPLOAD_ERR_OK) {
             throw new CM_Exception('File upload error: ' . self::$_uploadErrors[$fileInfo['error']]);
         }
         $fileTmp = new CM_File($fileInfo['tmp_name']);
         if ($fileTmp->getSize() > self::MAX_FILE_SIZE) {
             throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('File too big'));
         }
         $file = CM_File_UserContent_Temp::create($fileInfo['name'], $fileTmp->read());
         $fileTmp->delete();
         $query = $this->_request->getQuery();
         $preview = null;
         if (isset($query['field'])) {
             $field = CM_FormField_File::factory($query['field'], ['name' => 'file']);
             $field->validateFile($file);
             $preview = $this->getRender()->fetchViewTemplate($field, 'preview', array('file' => $file));
         }
         $return['success'] = array('id' => $file->getUniqid(), 'preview' => $preview);
     } catch (CM_Exception_FormFieldValidation $ex) {
         $return['error'] = array('type' => get_class($ex), 'msg' => $ex->getMessagePublic($this->getRender()));
     }
     $this->_setContent(json_encode($return, JSON_HEX_TAG));
     // JSON decoding in IE-iframe needs JSON_HEX_TAG
 }
Exemplo n.º 2
0
 /**
  * @param CM_File $file
  * @param string  $url
  * @throws CM_Exception
  * @codeCoverageIgnore
  */
 private function _download(CM_File $file, $url)
 {
     $url = (string) $url;
     if ($file->exists()) {
         $modificationTime = $file->getModified();
         if (time() - $modificationTime > self::CACHE_LIFETIME) {
             $file->delete();
         }
     }
     if (!$file->exists()) {
         $path = $file->getPathOnLocalFilesystem();
         $client = new \GuzzleHttp\Client();
         $client->get($url, ['timeout' => 600, 'save_to' => $path]);
     }
     $this->_streamOutput->writeln('Download completed.');
 }
Exemplo n.º 3
0
 protected function tearDown()
 {
     CMTest_TH::clearEnv();
     $this->_configInternalFile->delete();
 }