Exemple #1
0
 /**
  * @param string      $post_field
  * @param array       $allowed_mimetypes
  * @param array       $errors
  *
  * @return bool
  */
 public function storeUpload($post_field, $allowed_mimetypes = array(), &$errors)
 {
     $itemid = $this->getVar('itemid');
     if (empty($allowed_mimetypes)) {
         $allowed_mimetypes = $this->publisher->getMimetypeHandler()->getArrayByType();
     }
     $maxfilesize = $this->publisher->getConfig('maximum_filesize');
     $maxfilewidth = $this->publisher->getConfig('maximum_image_width');
     $maxfileheight = $this->publisher->getConfig('maximum_image_height');
     if (!is_dir(PublisherUtils::getUploadDir())) {
         mkdir(PublisherUtils::getUploadDir(), 0757);
     }
     $uploader = new XoopsMediaUploader(PublisherUtils::getUploadDir() . '/', $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
     if ($uploader->fetchMedia($post_field)) {
         $uploader->setTargetFileName($itemid . "_" . $uploader->getMediaName());
         if ($uploader->upload()) {
             $this->setVar('filename', $uploader->getSavedFileName());
             if ($this->getVar('name') == '') {
                 $this->setVar('name', $this->getNameFromFilename());
             }
             $this->setVar('mimetype', $uploader->getMediaType());
             return true;
         } else {
             $errors = array_merge($errors, $uploader->getErrors(false));
             return false;
         }
     } else {
         $errors = array_merge($errors, $uploader->getErrors(false));
         return false;
     }
 }