/**
  * validate upload field
  * @param string $field
  *
  * @return boolean
  */
 public function validate($field = null)
 {
     if (null == $field) {
         $field = $this->_field;
     }
     $valid = true;
     if (null == $field || !isset($_FILES[$field])) {
         $this->_error[] = 'Empty file upload or file upload not found in temp dir';
         return false;
     }
     $this->_dir = Folder::clean($this->_dir);
     if (null == $this->_dir) {
         $this->_error[] = 'Upload directory empty';
         $valid = false;
     }
     if (!is_dir($this->_dir) || !is_writeable($this->_dir)) {
         $this->_error[] = 'Upload directory not found or can not writable';
         $valid = false;
     }
     if ($_FILES[$field]['error'] != 0) {
         switch ($_FILES[$field]['error']) {
             case 1:
                 $this->_error[] = 'The file is too large (server)';
                 break;
             case 2:
                 $this->_error[] = 'The file is too large (form)';
                 break;
             case 3:
                 $this->_error[] = 'The file was only partially uploaded';
                 break;
             case 4:
                 $this->_error[] = 'No file was uploaded';
                 break;
             case 5:
                 $this->_error[] = 'The servers temporary folder is missing';
                 break;
             case 6:
                 $this->_error[] = 'Failed to write to the temporary folder';
                 break;
         }
         return false;
     }
     if (true === $this->_requiredCheckMimeType) {
         if (false === $this->checkMineType($field)) {
             $valid = false;
         }
     }
     //check file size
     if ($_FILES[$field]['size'] / (1024 * 1024) > $this->_maxSize) {
         $this->_error[] = 'File size (' . $_FILES[$field]['size'] / (1024 * 1024) . ') is too big (more than allowed size:' . $this->_maxSize . ' Mb)';
         $valid = false;
     }
     return $valid;
 }
Beispiel #2
0
 public function executeRemoveImg()
 {
     $file_name = $this->post('file_name');
     $item_id = $this->post('item_id');
     $res = new \AjaxResponse();
     $res->type = \AjaxResponse::ERROR;
     if (!$item_id || !($item = \Items::retrieveById($item_id))) {
         $res->message = t('Items not found');
         return $this->renderText($res->toString());
     }
     if ($file_name) {
         $file_path = MEDIA_DIR . '/product_img/' . $file_name;
         Folder::clean($file_path);
         $item->removeImage($file_name);
         if ($item->save(false)) {
             @unlink($file_path);
             $res->message = t('OK!');
             $res->type = \AjaxResponse::SUCCESS;
         } else {
             $res->message = t('Something went wrong, could not remove image');
         }
     }
     $item_img = $item->getImages();
     foreach ($item_img as &$img) {
         $img['url'] = rtrim($this->document()->getBaseUrl(), '/') . preg_replace('/(\\/+)/', '/', '/../' . $img['path']);
         $img['thumb_url'] = \Items::getImgThumbFromPath($img['path'], 52);
     }
     $res->images = $item_img;
     return $this->renderText($res->toString());
 }
Beispiel #3
0
 public function afterDelete()
 {
     @unlink(\Flywheel\Util\Folder::clean(MEDIA_DIR . $this->getPath()));
     return parent::afterDelete();
 }
 /**
  * validate upload field
  * @param string $field
  *
  * @return boolean
  */
 public function validate($field = null)
 {
     if (null == $field) {
         $field = $this->_field;
     }
     $valid = true;
     if (null == $field || !isset($_FILES[$field])) {
         $this->_error[] = 'Empty file upload or file upload not found in temp dir';
         return false;
     }
     $this->_dir = Folder::clean($this->_dir);
     if (null == $this->_dir) {
         $this->_error[] = 'Upload directory empty';
         $valid = false;
     }
     if (!is_dir($this->_dir) || !is_writeable($this->_dir)) {
         $this->_error[] = 'Upload directory not found or can not writable';
         $valid = false;
     }
     foreach ($this->_uploadData as $data) {
         if ($this->_valid($data) && $valid) {
             $valid = true;
         } else {
             $valid = false;
         }
     }
     return $valid;
 }