Example #1
0
 public function uploadInsert()
 {
     try {
         $parentId = $this->_controller->getEntity()->getAncestorId();
         $fileId = 'Filedata';
         $upload = new Sitengine_Upload($fileId);
         if (!$upload->isFile()) {
             return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
         } else {
             if ($upload->getError() > 0) {
                 switch ($upload->getError()) {
                     case 1:
                         # uploaded file exceeds the UPLOAD_MAX_FILESIZE directive in php.ini
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_SIZEEXCEEDED);
                     case 2:
                         # uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_SIZEEXCEEDED);
                     case 3:
                         # uploaded file was only partially uploaded
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_INCOMPLETE);
                     case 4:
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_NOFILE);
                     default:
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
                 }
             }
         }
         $id = Sitengine_String::createId();
         $this->_controller->getFrontController()->getBlogPackage()->getFilesTable()->handleInsertUploads($id);
         $date = new Zend_Date();
         $date->setTimezone('UTC');
         $dateStamp = $date->get('YYYY-MM-dd HH:mm:ss', Sitengine_Env::LANGUAGE_EN);
         $gid = $this->_controller->getPermiso()->getDirectory()->getGroupId($this->_controller->getFrontController()->getBlogPackage()->getOwnerGroup());
         $gid = !is_null($gid) ? $gid : Sitengine_Permiso::GID_ADMINISTRATORS;
         $permissions = $this->_controller->getFrontController()->getBlogPackage()->getFilesTable()->getDefaultPermissionData($this->_controller->getPermiso(), $this->_controller->getFrontController()->getBlogPackage()->getOwnerGroup());
         $data = array('titleLang0' => $upload->getName(), 'sorting' => '', 'publish' => 1, 'id' => $id, 'cdate' => $dateStamp, 'mdate' => $dateStamp, 'parentId' => $parentId);
         $data = array_merge($data, $permissions);
         $data = array_merge($data, $this->_controller->getFrontController()->getBlogPackage()->getFilesTable()->getFileData());
         return $this->_controller->getFrontController()->getBlogPackage()->getFilesTable()->insertOrRollback($data) ? 'OK' : 'Error';
     } catch (Exception $exception) {
         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
     }
 }
Example #2
0
 public function uploadToTempDir()
 {
     try {
         $fileId = 'Filedata';
         $upload = new Sitengine_Upload($fileId);
         if (!$upload->isFile()) {
             return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
         } else {
             if ($upload->getError() > 0) {
                 switch ($upload->getError()) {
                     case 1:
                         # uploaded file exceeds the UPLOAD_MAX_FILESIZE directive in php.ini
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_SIZEEXCEEDED);
                     case 2:
                         # uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_SIZEEXCEEDED);
                     case 3:
                         # uploaded file was only partially uploaded
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_INCOMPLETE);
                     case 4:
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_NOFILE);
                     default:
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
                 }
             }
         }
         $filename = preg_replace("/[^a-zA-Z0-9._-]/", "_", $upload->getName());
         $path = $this->_controller->getTempDir() . '/' . $filename;
         if (file_exists($path)) {
             return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_EXISTS);
         } else {
             if (is_uploaded_file($upload->getTempName())) {
                 if (move_uploaded_file($upload->getTempName(), $path)) {
                     @chmod($path, 0666);
                     return 'OK';
                 }
             }
         }
         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
     } catch (Exception $exception) {
         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
     }
 }
Example #3
0
 public function uploadToTempDir()
 {
     try {
         /*
                     # php setting to play with:
                     print 'upload_tmp_dir: '.ini_get('upload_tmp_dir').'<br />'; # PHP_INI_SYSTEM
         print 'file_uploads: '.ini_get('file_uploads').'<br />'; # PHP_INI_SYSTEM
         print 'upload_max_filesize: '.ini_get('upload_max_filesize').'<br />'; # PHP_INI_PERDIR
         print 'post_max_size: '.ini_get('post_max_size').'<br />'; # PHP_INI_PERDIR
         print 'max_input_time: '.ini_get('max_input_time').'<br />'; # PHP_INI_PERDIR
         print 'memory_limit: '.ini_get('memory_limit').'<br />'; # PHP_INI_ALL
         print 'max_execution_time: '.ini_get('max_execution_time').'<br />'; # PHP_INI_ALL
         
         # .htaccess php settings
         php_value upload_max_filesize 666M
         php_value post_max_size 777M
         php_value max_input_time 888
         php_value memory_limit 999
         
         # .htaccess apache settings
         LimitRequestBody
         
         # apache settings
         TimeOut
         */
         $fileId = 'Filedata';
         $upload = new Sitengine_Upload($fileId);
         if (!$upload->isFile()) {
             return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
         } else {
             if ($upload->getError() > 0) {
                 switch ($upload->getError()) {
                     case 1:
                         # uploaded file exceeds the UPLOAD_MAX_FILESIZE directive in php.ini
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_SIZEEXCEEDED);
                     case 2:
                         # uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_SIZEEXCEEDED);
                     case 3:
                         # uploaded file was only partially uploaded
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_INCOMPLETE);
                     case 4:
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_NOFILE);
                     default:
                         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
                 }
             }
         }
         $filename = preg_replace("/[^a-zA-Z0-9._-]/", "_", $upload->getName());
         $path = $this->_controller->getTempDir() . '/' . $filename;
         if (file_exists($path)) {
             return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_EXISTS);
         } else {
             if (is_uploaded_file($upload->getTempName())) {
                 if (move_uploaded_file($upload->getTempName(), $path)) {
                     @chmod($path, 0666);
                     return 'OK';
                 }
             }
         }
         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
     } catch (Exception $exception) {
         return $this->_controller->getTranslate()->translate(Sitengine_Env::STATUS_UPLOAD_ERROR);
     }
 }