예제 #1
0
 /**
  * @ORM\PostPersist
  */
 public function uploadFile2()
 {
     if (null === $this->file2) {
         return;
     } else {
         $this->file2->move(__DIR__ . '/../../../app/uploads' . $this->getUploadDir(), $this->second_fichier);
         unset($this->file2);
     }
 }
예제 #2
0
 /**
  * @ORM\PostPersist
  */
 public function upload()
 {
     if (null === $this->file) {
         return;
     }
     // if there is an error when moving the file, an exception will
     // be automatically thrown by move(). This will properly prevent
     // the entity from being persisted to the database on error
     $this->file->move($this->getUploadRootDir(), $this->photo);
     unset($this->file);
 }
예제 #3
0
 /**
  * Override base method.
  */
 public function save()
 {
     if (isset($this->file)) {
         $fileName = $this->entityId . '_' . $this->fieldId . '.' . $this->file->getClientOriginalExtension();
         $this->value = $fileName;
         $this->file->move(public_path() . config('asgard.dynamicfield.config.files-path'), $fileName);
     }
     parent::save();
 }
예제 #4
0
 public function upload()
 {
     // var_dump(pathinfo($this->file, PATHINFO_EXTENSION));die();
     if (null === $this->file) {
         return false;
     } else {
         $this->path = sha1(uniqid(mt_rand(), true)) . '.' . $this->file->guessExtension();
     }
     $this->file->move($this->getUploadRootDir(), $this->path);
     unset($this->file);
     return true;
 }
예제 #5
0
 /**
  * @ORM\PostPersist()
  * @ORM\PostUpdate()
  */
 public function upload()
 {
     if (null === $this->file) {
         return;
     }
     // s'il y a une erreur lors du déplacement du fichier, une exception
     // va automatiquement être lancée par la méthode move(). Cela va empêcher
     // proprement l'entité d'être persistée dans la base de données si
     // erreur il y a
     $this->file->move($this->getUploadRootDir(), $this->photo);
     unset($this->file);
 }
예제 #6
0
 /**
  * Make an image with the configuration parameter
  *
  * @return bool|string True if success or HTML string if requested
  */
 protected function build()
 {
     $ret = null;
     if (file::exists($this->cfg->file)) {
         $this->cfg->wAct = null;
         $this->cfg->hAct = null;
         if ($this->cfg->autoFileSave && empty($this->cfg->fileSave)) {
             $this->cfg->fileSave = $this->makePath($this->cfg->file, $this->cfg->fileSaveAdd);
         }
         if ($this->cfg->rebuild || !file::exists($this->cfg->fileSave)) {
             $this->setImg($this->cfg->file);
             $change = false;
             if (is_array($this->cfg->crop)) {
                 if ($this->crop($this->cfg->crop)) {
                     // Save the new size
                     $this->cfg->wAct = imagesx($this->imgAct);
                     $this->cfg->hAct = imagesy($this->imgAct);
                     $change = true;
                 }
             } else {
                 // Resize
                 if ($this->cfg->resizeSmaller || $this->cfg->w > 0 && $this->cfg->wAct > $this->cfg->w || $this->cfg->h > 0 && $this->cfg->hAct > $this->cfg->h) {
                     if ($this->resize(array('w' => $this->cfg->w, 'h' => $this->cfg->h, 'bgColor' => $this->cfg->bgColor, 'fit' => $this->cfg->fit, 'useMaxResize' => $this->cfg->useMaxResize))) {
                         // Save the new size
                         $this->cfg->wAct = imagesx($this->imgAct);
                         $this->cfg->hAct = imagesy($this->imgAct);
                         if ($this->cfg->w || $this->cfg->h) {
                             $change = true;
                         }
                     }
                 }
             }
             if (!empty($this->cfg->filters) && function_exists('imagefilter')) {
                 foreach ($this->cfg->filters as $prms) {
                     if (!is_array($prms)) {
                         $f = $prms;
                         $prms = array();
                     } else {
                         $f = array_shift($prms);
                     }
                     switch (count($prms)) {
                         case 0:
                             imagefilter($this->imgAct, $f);
                             break;
                         case 1:
                             imagefilter($this->imgAct, $f, $prms[0]);
                             break;
                         case 2:
                             imagefilter($this->imgAct, $f, $prms[0], $prms[1]);
                             break;
                         case 3:
                             imagefilter($this->imgAct, $f, $prms[0], $prms[1], $prms[2]);
                             break;
                         default:
                             imagefilter($this->imgAct, $f, $prms[0], $prms[1], $prms[2], $prms[3]);
                             break;
                     }
                 }
             }
             if ($this->cfg->grayFilter) {
                 // Copy form $img to $imgDst With the parameter defined, with grayscale
                 if (function_exists('imagefilter')) {
                     imagefilter($this->imgAct, IMG_FILTER_GRAYSCALE);
                 } else {
                     // Manual Grayscale
                     $imgTmp = $this->imgAct;
                     $x = imagesx($imgTmp);
                     $y = imagesy($imgTmp);
                     $this->imgAct = imagecreatetruecolor($x, $y);
                     imagecolorallocate($this->imgAct, 0, 0, 0);
                     for ($i = 0; $i < $x; $i++) {
                         for ($j = 0; $j < $y; $j++) {
                             $rgb = imagecolorat($imgTmp, $i, $j);
                             $r = $rgb >> 16 & 0xff;
                             $g = $rgb >> 8 & 0xff;
                             $b = $rgb & 0xff;
                             $color = max(array($r, $g, $b));
                             imagesetpixel($this->imgAct, $i, $j, imagecolorexact($this->imgAct, $color, $color, $color));
                         }
                     }
                     imagedestroy($imgTmp);
                 }
             }
             if (!empty($this->cfg->mask) && file::exists($this->cfg->mask)) {
                 $this->mask($this->cfg->mask);
                 $change = true;
             }
             if (!empty($this->cfg->watermarks) && is_array($this->cfg->watermarks)) {
                 foreach ($this->cfg->watermarks as $watermark) {
                     $tmp = $this->watermark($watermark);
                     $change = $change || $tmp;
                 }
             }
             $ret = null;
             if (!$change) {
                 $this->cfg->fileSave = $this->cfg->file;
             }
             if (!empty($this->cfg->fileSave)) {
                 if ($change) {
                     if ($this->save($this->cfg->fileSave)) {
                         $ret = $this->cfg->fileSave;
                     }
                 } else {
                     if ($this->cfg->file != $this->cfg->fileSave) {
                         file::move($this->cfg->file, $this->cfg->fileSave);
                     }
                     $ret = $this->cfg->fileSave;
                 }
             }
             if ($this->cfg->html) {
                 $ret = $this->html();
             }
         } else {
             if ($this->cfg->html) {
                 $ret = $this->html();
             } else {
                 $ret = $this->cfg->fileSave;
             }
         }
     }
     return $ret;
 }