Example #1
0
 /**
  * @return $this
  */
 public function upload()
 {
     foreach ($this->files as $file) {
         $moveFile = $this->config['path'] . DIRECTORY_SEPARATOR . $file->getHash() . '.' . $file->getOriginalExtension();
         if (!file_exists($moveFile)) {
             if (!move_uploaded_file($file->getTmpName(), $moveFile)) {
                 continue;
             }
         }
         $uploaded = new File($moveFile);
         $uploaded->setHash($file->getHash());
         $uploaded->setOriginalName($file->getName());
         $uploaded->setOriginalExtension($file->getOriginalExtension());
         $uploaded->setRelativePath(str_replace(realpath('./') . DIRECTORY_SEPARATOR, '', realpath($moveFile)));
         $this->uploadedInfo[] = $uploaded;
     }
     unset($uploaded);
     return $this;
 }