예제 #1
5
 /**
  * @param AssetInterface $asset
  * @param UploadedFile   $file
  *
  * @return AssetVersion
  */
 public function createVersionFromFile(AssetInterface $asset, UploadedFile $file)
 {
     list($width, $height) = getimagesize($file->getRealPath());
     $extension = File::extension($file->getClientOriginalName(), $file->getMimetype());
     $version = $this->version->create(['asset_id' => $asset->getId(), 'extension' => $extension, 'filesize' => $file->getClientSize(), 'filename' => $file->getClientOriginalName(), 'width' => $width, 'height' => $height, 'edited_at' => time(), 'edited_by' => Auth::getPerson()->getId(), 'mimetype' => $file->getMimeType(), 'metadata' => File::exif($file->getRealPath())]);
     $file->move($asset->directory(), $version->id);
     return $version;
 }
예제 #2
1
 /**
  * Orientate the image.
  *
  * @param UploadedFile $file
  * @param              $orientation
  * @return UploadedFile
  */
 protected function orientate(UploadedFile $file, $orientation)
 {
     $image = imagecreatefromjpeg($file->getRealPath());
     switch ($orientation) {
         case 2:
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 3:
             $image = imagerotate($image, 180, 0);
             break;
         case 4:
             $image = imagerotate($image, 180, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 5:
             $image = imagerotate($image, -90, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 6:
             $image = imagerotate($image, -90, 0);
             break;
         case 7:
             $image = imagerotate($image, 90, 0);
             imageflip($image, IMG_FLIP_HORIZONTAL);
             break;
         case 8:
             $image = imagerotate($image, 90, 0);
             break;
     }
     imagejpeg($image, $file->getRealPath(), 90);
     return new UploadedFile($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType(), $file->getSize());
 }
예제 #3
1
 /**
  * {@inheritdoc}
  *
  * @param null|\Symfony\Component\HttpFoundation\File\UploadedFile $data
  */
 public function convertFieldValueFromForm($data)
 {
     if ($data === null) {
         return null;
     }
     return array("inputUri" => $data->getRealPath(), "fileName" => $data->getClientOriginalName(), "fileSize" => $data->getSize());
 }
예제 #4
1
 /**
  * {@inheritdoc}
  */
 public function saveFile(UploadedFile $uploadedFile, $fileName)
 {
     $stream = fopen($uploadedFile->getRealPath(), 'r+');
     $result = $this->filesystem->writeStream($this->getMediaBasePath() . '/' . $fileName . '.' . $uploadedFile->guessClientExtension(), $stream);
     fclose($stream);
     return $result;
 }
 /**
  * @param UploadedFile $file
  * @return string
  */
 public function compress(UploadedFile $file)
 {
     $shell = new Exec();
     $command = new Command(sprintf($this->command, $file->getRealPath(), 'compressed'));
     $shell->run($command);
     if (!file_exists($file->getRealPath() . 'compressed')) {
         throw new \RuntimeException('No compressed Image created!');
     }
     return $file->getRealPath() . 'compressed';
 }
 /**
  * Process image file, make it progressive
  * @param UploadedFile $file
  */
 public function processFile(UploadedFile $file)
 {
     $this->file = $file;
     foreach (self::$IMAGE_TYPES as $type) {
         if (in_array($this->file->getMimeType(), $type['mime_types'])) {
             $filePath = $this->file->getRealPath();
             $typeObject = new $type['class']($filePath);
             $typeObject->process();
             break;
         }
     }
 }
예제 #7
0
 /**
  * Save the profile photo
  * 
  * @param  \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @return Boolean 
  */
 public function savePhoto(UploadedFile $file)
 {
     if (!$file->isValid()) {
         return false;
     }
     try {
         $this->photo = md5_file($file->getRealPath());
         $this->save();
         Storage::disk()->put($this->photo, file_get_contents($file->getRealPath()));
         return true;
     } catch (\Exception $e) {
         Log::error('Failed saving photo to user\'s profile: ' . $e->getMessage());
         return false;
     }
 }
예제 #8
0
 public function execute()
 {
     if ($this->photo->isValid()) {
         $name = sha1($this->user->getId() . $this->user->getLogin() . $this->user->getRegisteredAt() . time() . uniqid('ffdf'));
         $photoUploader = new PhotoFormatter($this->photo->getRealPath(), self::MINIMUM_SIZE, self::MAXIMUM_SIZE, $this->output);
         $old = $this->user->getAvatar();
         $photoUploader->setNewName($name);
         $photoUploader->loadAndScale(self::START_SIZE);
         $this->user->setAvatar($name);
         $this->repository->update($this->user);
         if (!empty($old)) {
             $photoUploader->removeOld($old, self::START_SIZE);
         }
     }
 }
예제 #9
0
 public function getFileMd5Name(UploadedFile $file)
 {
     $ext = $file->guessExtension();
     $md5 = md5_file($file->getRealPath());
     $name = $md5 . '.' . $ext;
     return $name;
 }
예제 #10
0
 /**
  * 회원의 프로필 이미지를 등록한다.
  *
  * @param UserInterface $user        프로필 이미지를 등록할 회원
  * @param UploadedFile  $profileFile 프로필 이미지 파일
  *
  * @return string 등록한 프로필이미지 ID
  */
 public function updateUserProfileImage(UserInterface $user, UploadedFile $profileFile)
 {
     $disk = array_get($this->profileImgConfig, 'storage.disk');
     $path = array_get($this->profileImgConfig, 'storage.path');
     $size = array_get($this->profileImgConfig, 'size');
     // make fitted image
     /** @var ImageManager $imageManager */
     $imageManager = call_user_func($this->imageManagerResolver);
     $image = $imageManager->make($profileFile->getRealPath());
     $image = $image->fit($size['width'], $size['height']);
     // remove old profile image
     if (!empty($user->profileImageId)) {
         $file = File::find($user->profileImageId);
         if ($file !== null) {
             try {
                 $this->storage->remove($file);
             } catch (\Exception $e) {
             }
         }
     }
     // save image to storage
     $id = $user->getId();
     $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk);
     return $file->id;
 }
예제 #11
0
 /**
  * Create a new job instance.
  *
  * @param UploadedFile $image
  * @param null $filename (Without fileextension)
  * @param null $folder (Format: 'example/')
  */
 public function __construct(UploadedFile $image, $filename = null, $folder = null)
 {
     $this->realPath = $image->getRealPath();
     $this->extension = $image->getClientOriginalExtension();
     $this->filename = $this->getFilename($image, $filename);
     $this->folder = $folder;
 }
예제 #12
0
 /**
  * {@inheritDoc}
  */
 protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name)
 {
     $fs = $this->getFilesystem($mapping);
     $path = !empty($dir) ? $dir . '/' . $name : $name;
     $stream = fopen($file->getRealPath(), 'r+');
     $fs->writeStream($path, $stream, array('mimetype' => $file->getMimeType()));
 }
예제 #13
0
 public function store(UploadedFile $file)
 {
     $file->getClientOriginalName();
     $fileResult = \DB::table('file')->where('name', $file->getClientOriginalName())->where('checksum', md5_file($file->getRealPath()))->first();
     if (isset($fileResult->id)) {
         return $fileResult;
     }
     $fileResult = new Models\file();
     $fileResult->name = $file->getClientOriginalName();
     $fileResult->size = $file->getSize();
     $fileResult->mime_type = $file->getMimeType();
     $fileResult->checksum = md5_file($file->getRealPath());
     $fileResult->save();
     $fileResult->path = $this->moveFile($file, $fileResult->id);
     $fileResult->save();
     return $fileResult;
 }
예제 #14
0
 /**
  * Upload a single file.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  *
  * @param string $target
  * @return string
  */
 protected function uploadSingleFile($file, $target = null)
 {
     $filename = uniqid() . '.' . $file->getClientOriginalExtension();
     $filename = $target ? $target . '/' . $filename : $filename;
     $content = file_get_contents($file->getRealPath());
     $this->flysystem->write($filename, $content);
     return cloudfront_asset($filename);
 }
예제 #15
0
 /**
  * @param string $containerName
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param string|null $relativePath
  *
  * @return bool
  */
 public function saveUploadedFile($containerName, UploadedFile $file, $relativePath)
 {
     if ($file->isValid() === false) {
         return false;
     }
     $fileName = $file->getClientOriginalName();
     $filePath = $this->getFullFileName($containerName, $fileName);
     return $this->move($file->getRealPath(), $filePath);
 }
예제 #16
0
 public function create(UploadedFile $file, User $user)
 {
     $filename = sha1(rand(11111, 99999));
     $extension = $file->getClientOriginalExtension();
     Storage::put('images/' . $filename . '.' . $extension, file_get_contents($file->getRealPath()));
     $image = new Image(['user_id' => $user->id, 'filename' => $file->getClientOriginalName(), 'path' => $filename . '.' . $extension, 'mime_type' => $file->getMimeType(), 'location' => 'local', 'status' => Image::STATUS_PENDING]);
     $image->save();
     return $image;
 }
예제 #17
0
 /**
  * Upload a file.
  *
  * @param UploadedFile    $file
  * @param FolderInterface $folder
  * @return bool|FileInterface
  */
 public function upload(UploadedFile $file, FolderInterface $folder)
 {
     $rules = 'required';
     if ($allowed = $folder->getAllowedTypes()) {
         $rules .= '|mimes:' . implode(',', $allowed);
     }
     $validation = $this->validator->make(['file' => $file], ['file' => $rules]);
     if (!$validation->passes()) {
         return false;
     }
     $disk = $folder->getDisk();
     /* @var FileInterface $entry */
     $entry = $this->manager->put($disk->getSlug() . '://' . $folder->getSlug() . '/' . $file->getClientOriginalName(), file_get_contents($file->getRealPath()));
     if (in_array($entry->getExtension(), $this->config->get('anomaly.module.files::mimes.types.image'))) {
         $size = getimagesize($file->getRealPath());
         $this->files->save($entry->setAttribute('width', $size[0])->setAttribute('height', $size[1]));
     }
     return $entry;
 }
예제 #18
0
 /**
  * Upload file to S3
  *
  * @author Casper Rasmussen <*****@*****.**>
  * @access protected
  * @param  \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
  * @param  \Nodes\Assets\Upload\Settings                       $settings
  * @return string
  * @throws \Nodes\Assets\Upload\Exceptions\AssetsUploadFailedException
  */
 protected function store(UploadedFile $uploadedFile, Settings $settings)
 {
     try {
         // Upload to bucket
         \Storage::disk('s3')->put($settings->getFilePath(), file_get_contents($uploadedFile->getRealPath()));
     } catch (\Exception $e) {
         throw new AssetsUploadFailedException('Could not upload file to Amazon S3. Reason: ' . $e->getMessage());
     }
     return $settings->getFilePath();
 }
예제 #19
0
 protected function makeThumbnail(UploadedFile $photo)
 {
     $filename = sprintf('%s-%s', time(), str_replace(' ', '-', $photo->getClientOriginalName()));
     $image = Image::make($photo->getRealPath());
     $image->resize(800, null, function ($constraint) {
         $constraint->aspectRatio();
     })->save($this->fullPath($filename))->stream();
     Storage::disk('s3')->put($this->uploadsDirectory . $filename, $image->__toString());
     return $filename;
 }
예제 #20
0
 protected function makeThumbnail(UploadedFile $photo)
 {
     $filename = sprintf('%s-%s', time(), $photo->getClientOriginalName());
     //87947839749.jpg
     $image = Image::make($photo->getRealPath());
     $image->resize(800, null, function ($constraint) {
         $constraint->aspectRatio();
     })->save($this->fullPath($filename));
     return $filename;
 }
예제 #21
0
 /**
  * Creates a file object from a file an uploaded file.
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
  */
 public function fromPost($uploadedFile)
 {
     if ($uploadedFile === null) {
         return;
     }
     $this->file_name = $uploadedFile->getClientOriginalName();
     $this->file_size = $uploadedFile->getClientSize();
     $this->content_type = $uploadedFile->getMimeType();
     $this->disk_name = $this->getDiskName();
     $this->putFile($uploadedFile->getRealPath(), $this->disk_name);
 }
 public function __construct(UploadedFile $file, $container)
 {
     parent::__construct($file->getRealPath(), $container);
     $this->qb = $this->_em->createQueryBuilder();
     $this->file = $file;
     $this->customer = $this->_em->getRepository('CoreBundle:Customer')->findOneBy(['abbr' => $this->_container->getParameter('sportmaster_abbr')]);
     if (!$this->customer) {
         throw new \Exception("Cant find customer by abbr {$this->_container->getParameter('sportmaster_abbr')}");
     }
     $this->messageService = new MessageCollectionService();
     $this->vendors = $this->getVendors();
 }
예제 #23
0
파일: Magus.php 프로젝트: s1dd/magus
 /**
  * Parses CSV into an associative array.
  * 
  * @param  \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @return array 
  */
 public function parse(\Symfony\Component\HttpFoundation\File\UploadedFile $file)
 {
     ini_set("auto_detect_line_endings", "1");
     $handle = fopen($file->getRealPath(), 'r');
     $fields = fgetcsv($handle);
     while (($row = fgetcsv($handle)) != false) {
         for ($i = 0; $i < count($fields); $i++) {
             $rowData[$fields[$i]] = $row[$i];
         }
         $data[] = $rowData;
     }
     return count($data) === 1 ? $data[0] : $data;
 }
예제 #24
0
 public function run(UploadedFile $file)
 {
     $extension = $file->getClientOriginalExtension();
     // Create filename
     $filename = $this->generateImagename($extension);
     // Create image file path
     $this->image_path = $this->folder . "/" . $filename;
     foreach ($this->sizes as $key => $size) {
         $this->createSizeFolder($key);
         $this->resizeAndSave($file->getRealPath(), $key, $size);
     }
     return array("path" => $this->image_path, "extension" => $extension);
 }
 /**
  * Add new file
  *
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @return bool
  */
 public function add(UploadedFile $file)
 {
     $name = rand(111111, 999999);
     $extension = pathinfo($file->getClientOriginalName(), PATHINFO_EXTENSION);
     $path = "{$this->path}{$name}.{$extension}";
     if (!$this->filesystem->put($path, file_get_contents($file->getRealPath()))) {
         return false;
     }
     if (!$this->repo->create(['path' => $path])) {
         return false;
     }
     return true;
 }
예제 #26
0
 /**
  * @param UploadedFile $file
  * @param Model        $model
  *
  * @return bool
  */
 protected function hasFile(UploadedFile $file, Model $model)
 {
     $md5 = md5_file($file->getRealPath());
     $name = $file->getClientOriginalName();
     $class = get_class($model);
     $count = Auth::user()->attachments()->where('md5', $md5)->where('attachable_id', $model->id)->where('attachable_type', $class)->count();
     if ($count > 0) {
         $msg = trans('validation.file_already_attached', ['name' => $name]);
         $this->errors->add('attachments', $msg);
         return true;
     }
     return false;
 }
예제 #27
0
 /**
  * Try parse file by SimpleXml
  *
  * @param UploadedFile $file
  *
  * @return bool|int
  */
 public function import(UploadedFile $file)
 {
     try {
         $this->xml = simplexml_load_file($file->getRealPath(), 'SimpleXMLElement', LIBXML_PARSEHUGE | LIBXML_NOCDATA);
         $this->xml = json_decode(json_encode($this->xml), true);
         if ($this->xml && $this->isEvernote()) {
             $this->process();
             return $this->notebook->id;
         }
     } catch (Exception $e) {
         return false;
     }
     return false;
 }
 public function uploadAttachment(UploadedFile $uploadedFile = null, $profile = 'default')
 {
     if ($uploadedFile == null) {
         return null;
     }
     $folder = $this->filelib->getFolderOperator()->createByUrl($this->config['folder']);
     // Prepare file upload
     $upload = $this->filelib->getFileOperator()->prepareUpload($uploadedFile->getRealPath());
     // Override file name with info from client
     $upload->setOverrideFilename($uploadedFile->getClientOriginalName());
     // Upload file
     $file = $this->filelib->getFileOperator()->upload($upload, $folder, $profile);
     return $file;
 }
예제 #29
0
 /**
  * Unzip a module file.
  *
  * @param UploadedFile $file
  *
  * @return string|bool the path where the module has been extracted or false if an error has occured
  */
 protected function unzipModule(UploadedFile $file)
 {
     $extractPath = false;
     $zip = new ZipArchive();
     if ($zip->open($file->getRealPath()) === true) {
         $extractPath = $this->tempdir();
         if ($extractPath !== false) {
             if ($zip->extractTo($extractPath) === false) {
                 $extractPath = false;
             }
         }
         $zip->close();
     }
     return $extractPath;
 }
  protected function validatePdfUpload(array &$form, FormStateInterface &$form_state, UploadedFile $file_upload, $file_field_name) {
    /**
     * @var $file_upload \Symfony\Component\HttpFoundation\File\UploadedFile
     */
    if ($file_upload && $file_upload->isValid()) {
      // Move it to somewhere we know.
      $uploaded_filename = $file_upload->getClientOriginalName();

      // Ensure the destination is unique; we deliberately use managed files,
      // but they are keyed on file URI, so we can't save the same one twice.
      $scheme = $this->config('fillpdf.settings')->get('scheme');
      $destination = file_destination(FillPdf::buildFileUri($scheme, 'fillpdf/' . $uploaded_filename), FILE_EXISTS_RENAME);

      // Ensure our directory exists.
      $fillpdf_directory = FillPdf::buildFileUri($scheme, 'fillpdf');
      $directory_exists = file_prepare_directory($fillpdf_directory, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS);

      if ($directory_exists) {
        $file_moved = $this->fileSystem->moveUploadedFile($file_upload->getRealPath(), $destination);

        if ($file_moved) {
          // Create a File object from the uploaded file.
          $new_file = File::create([
            'uri' => $destination,
            'uid' => $this->currentUser()->id(),
          ]);

          $errors = file_validate_extensions($new_file, 'pdf');

          if (count($errors)) {
            $form_state->setErrorByName('upload_pdf', $this->t('Only PDF files are supported, and they must end in .pdf.'));
          }
          else {
            $form_state->setValue('upload_pdf', $new_file);
          }
        }
        else {
          $form_state->setErrorByName('upload_pdf', $this->t("Could not move your uploaded file from PHP's temporary location to Drupal file storage."));
        }
      }
      else {
        $form_state->setErrorByName('upload_pdf', $this->t('Could not automatically create the <em>fillpdf</em> subdirectory. Please create this manually before uploading your PDF form.'));
      }
    }
    else {
      $form_state->setErrorByName('upload_pdf', $this->t('Your PDF could not be uploaded. Did you select one?'));
    }
  }