コード例 #1
0
ファイル: design.php プロジェクト: MrJookie/pm
 /**
  * Method to check for upload errors
  *
  * @param     array      $files    The files to check
  *
  * @return    boolean              True if no error
  */
 protected function checkFileError(&$files, $record_id = 0)
 {
     foreach ($files as &$file) {
         // Uploading a file is not required when updating an existing record
         if ($file['error'] == 4 && $record_id > 0) {
             $file['error'] = 0;
         }
         if ($file['error']) {
             $error = PFdesignsHelper::getFileErrorMsg($file['error'], $file['name']);
             $this->setError($error);
             $this->setMessage($error, 'error');
             return false;
         }
     }
     return true;
 }
コード例 #2
0
ファイル: revision.php プロジェクト: MrJookie/pm
 /**
  * Method for uploading a file
  *
  * @param     array      $file       The file information
  * @param     integer    $project    The project id
  * @param     boolean    $stream     If set to true, use data stream
  *
  * @return    mixed                  Array with file info on success, otherwise False
  */
 public function upload($file = NULL, $project = 0, $stream = false)
 {
     $uploadpath = PFdesignsHelper::getBasePath($project);
     if (!is_array($file)) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_NO_FILE_SELECTED'));
         return false;
     }
     if (!isset($file['tmp_name'])) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_NO_FILE_SELECTED'));
         return false;
     }
     // Try to create the upload path destination
     if (!JFolder::exists($uploadpath)) {
         if (!JFolder::create($uploadpath)) {
             return false;
         }
     }
     $errnum = (int) $file['error'];
     if ($errnum > 0) {
         $errmsg = PFdesignsHelper::getFileErrorMsg($errnum, $file['name'], $file['size']);
         $this->setError($errmsg);
         return false;
     }
     $name = $this->generateNewFileName($uploadpath, $file['name']);
     $ext = strtolower(JFile::getExt($name));
     if (!in_array($ext, array('jpeg', 'jpg', 'png', 'gif'))) {
         $this->setError(JText::_('COM_PFDESIGNS_WARNING_FILE_TYPE_NOT_SUPPORTED'));
         return false;
     }
     // Check mime type
     $info = getimagesize($file['tmp_name']);
     if (!$info) {
         $this->setError(JText::_('COM_PROJECTFORK_ERROR_FILE_FORMAT_NOT_SUPPORTED'));
         return false;
     }
     if (!in_array($info[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         $this->setError(JText::_('COM_PROJECTFORK_ERROR_FILE_FORMAT_NOT_SUPPORTED'));
         return false;
     }
     if (JFile::upload($file['tmp_name'], $uploadpath . '/' . $name, $stream) === true) {
         return array('name' => $name, 'size' => $file['size'], 'extension' => $ext);
     }
     return false;
 }