Example #1
0
 }
 public function getAbsolutePath()
 {
     return null === $this->path ? null : $this->getUploadRootDir() . '/' . $this->path;
 }
 public function getAssetPath()
 {
     if ($this->path == null) {
         return 'uploads/images/400x300.png';
     } else {
         return 'uploads/images/' . $this->path;
Example #2
0
 public function process()
 {
     if ($this->options['delete_old'] && $this->old_file !== $this->getFileAbsolutePath()) {
         $this->removeFile($this->old_file);
     }
     if (null === $this->file) {
         return;
     }
     //        echo "<pre>";\Doctrine\Common\Util\Debug::dump(realpath(__DIR__ . '/../../../../../web/media/uploads/g'), 5);die("</pre>");
     $this->file->move($this->entity->getUploadDir(), $this->entity->getPath());
 }
Example #3
0
 /**
  * Move File to a temporary storage directory for processing
  * temporary directory must have 0755 permissions in order to be processed
  *
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $csv_import
  * @return Symfony\Component\HttpFoundation\File $moved_file
  */
 private function moveFile($csv_import)
 {
     // Check if directory exists make sure it has correct permissions, if not make it
     $destination_directory = storage_path('imports/tmp');
     if (is_dir($destination_directory)) {
         //chmod($destination_directory, 0755);
     } else {
         //mkdir($destination_directory, 0755, true);
     }
     // Get file's original name
     $original_file_name = $csv_import->getClientOriginalName();
     // Return moved file as File object
     return $csv_import->move($destination_directory, $original_file_name);
 }
Example #4
0
 public function upload()
 {
     // the file property can be empty if the field is not required
     if (null === $this->file) {
         return;
     }
     // set the path property to the filename where you will save the file
     $this->setUrl(uniqid() . '.' . $this->file->guessExtension());
     // we use the original file name here but you should
     // sanitize it at least to avoid any security issues
     // move takes the target directory and then the target filename to move to
     $this->file->move($this->getUploadRootDir(), $this->getUrl());
     // clean up the file property as you won't need it anymore
     $this->file = null;
 }
Example #5
0
 /**
  * Save given file
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param                                                     $path
  *
  * @return array
  * @throws Exception
  */
 function save_file(Symfony\Component\HttpFoundation\File\UploadedFile $file, $path)
 {
     $fileName = sprintf("%d_%s", time(), str_replace(' ', '_', $file->getClientOriginalName()));
     if (File::exists("{$path}/{$fileName}")) {
         throw new Exception('File already exists!');
     }
     if (!File::isDirectory($path)) {
         File::makeDirectory($path, 755, true);
     }
     if (!$file->move($path, $fileName)) {
         throw new Exception('Failed to save!');
     }
     return ['filename' => $fileName, 'size' => $file->getSize()];
 }
Example #6
0
 /**
  * Upload file to server
  *
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param boolean $isImage
  *
  * @return string
  */
 public static function uploadFile($file, $isImage = true)
 {
     $newFileName = self::createNewFileName($file->getClientOriginalName());
     $finalFileName = $newFileName . '.' . $file->getClientOriginalExtension();
     if ($isImage) {
         $uploadDir = self::getImageUploadPath();
         $returnFileName = $newFileName;
     } else {
         $uploadDir = self::getFileUploadPath();
         $returnFileName = $finalFileName;
     }
     // Upload file to server
     $uploadFile = $file->move($uploadDir, $finalFileName);
     if (empty($uploadFile)) {
         return '';
     }
     if ($isImage) {
         // Create thumbnail image
         $thumbWidth = Config::get('app.image_sizes.size.thumb');
         $thumbName = Config::get('app.image_sizes.name.thumb') . $finalFileName;
         copy($uploadDir . $finalFileName, $uploadDir . $thumbName);
         $thumbImage = ResizeImage::make($uploadDir . $thumbName);
         $thumbImage->orientate();
         $thumbImage->fit($thumbWidth)->save($uploadDir . $thumbName);
     }
     return $returnFileName;
 }