public function saveAvatar($pk, $file)
 {
     if (!PFImage::isValid($file['name'], $file['tmp_name'])) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_NOT_AN_IMAGE'));
         return false;
     }
     // Delete any previous avatar
     if (!$this->deleteAvatar($pk)) {
         return false;
     }
     if ($file['error']) {
         $error = PFrepoHelper::getFileErrorMsg($file['error'], $file['name']);
         $this->setError($error);
         return false;
     }
     $uploadpath = JPATH_ROOT . '/media/com_projectfork/repo/0/avatar';
     $name = $pk . '.' . strtolower(JFile::getExt($file['name']));
     if (JFile::upload($file['tmp_name'], $uploadpath . '/' . $name) === true) {
         return true;
     }
     return false;
 }
Beispiel #2
0
 public function saveLogo($file = NULL, $pk = NULL)
 {
     $pk = !empty($pk) ? (int) $pk : (int) $this->getState($this->getName() . '.id');
     if (empty($file)) {
         $file_form = JRequest::getVar('jform', '', 'files', 'array');
         if (is_array($file_form)) {
             if (isset($file_form['name']['attribs']['logo'])) {
                 if ($file_form['name']['attribs']['logo'] == '') {
                     return true;
                 }
                 $file = array();
                 $file['name'] = $file_form['name']['attribs']['logo'];
                 $file['type'] = $file_form['type']['attribs']['logo'];
                 $file['tmp_name'] = $file_form['tmp_name']['attribs']['logo'];
                 $file['error'] = $file_form['error']['attribs']['logo'];
                 $file['size'] = $file_form['size']['attribs']['logo'];
                 if ($file['error']) {
                     if (PFApplicationHelper::exists('com_pfrepo')) {
                         $error = PFrepoHelper::getFileErrorMsg($file['error'], $file['name']);
                         $this->setError($error);
                     }
                     return false;
                 }
             }
         }
         if (empty($file)) {
             return true;
         }
     }
     if (!$pk) {
         return false;
     }
     if (empty($file)) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_NO_FILE_SELECTED'));
         return false;
     }
     if (!PFImage::isValid($file['name'], $file['tmp_name'])) {
         $this->setError(JText::_('COM_PROJECTFORK_WARNING_NOT_AN_IMAGE'));
         return false;
     }
     // Delete any previous logo
     if (!$this->deleteLogo($pk)) {
         return false;
     }
     $uploadpath = JPATH_ROOT . '/media/com_projectfork/repo/0/logo';
     $name = $pk . '.' . strtolower(JFile::getExt($file['name']));
     if (JFile::upload($file['tmp_name'], $uploadpath . '/' . $name) === true) {
         return true;
     }
     return false;
 }