Exemplo n.º 1
4
 /**
  * Import file and find Stories inside
  * This method will select automatically the best way to find stories
  * depending the kind of file uploaded
  *
  * @param UploadedFile $file XML or XLS file from Jira
  * @return bool True if stories found, False in the other case
  */
 public function importFromFile(UploadedFile $file)
 {
     if ('text/xml' === $file->getClientMimeType() or 'text/html' === $file->getClientMimeType()) {
         $this->importFromXML($file);
     } elseif ('application/octet-stream' === $file->getClientMimeType() or 'application/vnd.ms-excel' === $file->getClientMimeType() or 'application/msexcel' === $file->getClientMimeType() or 'application/x-msexcel' === $file->getClientMimeType() or 'application/x-ms-excel' === $file->getClientMimeType() or 'application/x-excel' === $file->getClientMimeType() or 'application/x-dos_ms_excel' === $file->getClientMimeType() or 'application/xls' === $file->getClientMimeType() or 'application/x-xls' === $file->getClientMimeType() or 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' === $file->getClientMimeType()) {
         /* 
         Because mine type detection doesn't work perfectly, at this time we don't know
         if the file is a classic XLS or a HTML XLS (XLSx)
         
         First we try to analyse it as a classical XLS file, if the file isn't an XLS file
         an exception will be thrown and we will try to check it as an HTML file (Jira HTML).
         
         Finally if the file isn't an Excel or a Jira HTML File an exception will be thrown
         and has to be catch by the parent method.
         */
         try {
             $this->importFromXLS($file);
         } catch (\Exception $e) {
             $this->importFromHTML($file);
         }
     } else {
         // Delete the temporary file
         unlink($file->getRealPath());
         throw new \Symfony\Component\HttpFoundation\File\Exception\FileException();
     }
     // Delete the temporary file
     unlink($file->getRealPath());
     if (count($this->stories->getStories()) > 0) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Create a base file model class
  *
  * @return File
  */
 protected function makeFileRecord()
 {
     $file = new File();
     $file->fileable_type = $this->fileable_type;
     $file->fileable_id = $this->fileable_id;
     $file->filename = $this->timestamp . '-' . $this->file->getClientOriginalName();
     $file->filetype = $this->file->getClientMimeType();
     $file->filepath = $file->getURLPath() . $file->filename;
     $file->order = 0;
     return $file;
 }
Exemplo n.º 3
0
 public function upload(UploadedFile $file, $path)
 {
     // Check if the file's mime type is in the list of allowed mime types.
     if (!in_array($file->getClientMimeType(), self::$allowedMimeTypes)) {
         throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getClientMimeType()));
     }
     $adapter = $this->filesystem->getAdapter();
     $adapter->setMetadata($path, array('contentType' => $file->getClientMimeType()));
     $adapter->write($path, file_get_contents($file->getPathname()));
     return $path;
 }
 public function upload(UploadedFile $file, $path = null)
 {
     // Check if the file's mime type is in the list of allowed mime types.
     if (!in_array($file->getClientMimeType(), self::$allowedMimeTypes)) {
         throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getClientMimeType()));
     }
     if ($path) {
         $filename = sprintf('%s/%s.%s', $path, md5(time() * rand(0, 99)), $file->getClientOriginalExtension());
     } else {
         $filename = sprintf('%s/%s/%s/%s.%s', date('Y'), date('m'), date('d'), md5(time() * rand(0, 99)), $file->getClientOriginalExtension());
     }
     $adapter = $this->filesystem->getAdapter();
     $adapter->setMetadata($filename, array('contentType' => $file->getClientMimeType()));
     $adapter->write($filename, file_get_contents($file->getPathname()));
     return $filename;
 }
Exemplo n.º 5
0
 /**
  * Handle the file upload. Returns the array on success, or false
  * on failure.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param String $path where to upload file
  * @return array|bool
  */
 public function handle(UploadedFile $file, $path = 'uploads')
 {
     $input = array();
     $fileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
     // Detect and transform Croppa pattern to avoid problem with Croppa::delete()
     $fileName = preg_replace('#([0-9_]+)x([0-9_]+)#', "\$1-\$2", $fileName);
     $input['path'] = $path;
     $input['extension'] = '.' . $file->getClientOriginalExtension();
     $input['filesize'] = $file->getClientSize();
     $input['mimetype'] = $file->getClientMimeType();
     $input['filename'] = $fileName . $input['extension'];
     $fileTypes = Config::get('file.types');
     $input['type'] = $fileTypes[strtolower($file->getClientOriginalExtension())];
     $filecounter = 1;
     while (file_exists($input['path'] . '/' . $input['filename'])) {
         $input['filename'] = $fileName . '_' . $filecounter++ . $input['extension'];
     }
     try {
         $file->move($input['path'], $input['filename']);
         list($input['width'], $input['height']) = getimagesize($input['path'] . '/' . $input['filename']);
         return $input;
     } catch (FileException $e) {
         Notification::error($e->getmessage());
         return false;
     }
 }
Exemplo n.º 6
0
 /**
  * converts UploadedFile to $_FILES array
  *
  * @return array
  */
 public function getFileArray()
 {
     $array = array('name' => $this->uploaded_file->getClientOriginalName(), 'type' => $this->uploaded_file->getClientMimeType(), 'tmp_name' => $this->uploaded_file->getPath() . $this->getOSDirectorySeparator() . $this->uploaded_file->getFilename(), 'error' => $this->uploaded_file->getError(), 'size' => $this->uploaded_file->getSize(), 'dimension' => array('width' => 0, 'height' => 0));
     if (preg_match('/^image/', $array['type'])) {
         list($array['dimension']['width'], $array['dimension']['height']) = getimagesize($this->uploaded_file);
     }
     return $array;
 }
Exemplo n.º 7
0
 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         throw new \InvalidArgumentException('File slug already exists');
     }
     return $this->model->create(['filename' => $fileName, 'path' => "/assets/media/{$fileName}", 'extension' => $file->guessClientExtension(), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize()]);
 }
Exemplo n.º 8
0
 /**
  * @param UploadedFile $file
  *
  * @return \WellCommerce\Bundle\MediaBundle\Entity\MediaInterface
  */
 protected function createMediaFromUploadedFile(UploadedFile $file)
 {
     $media = $this->initResource();
     $media->setName($file->getClientOriginalName());
     $media->setExtension($file->guessClientExtension());
     $media->setMime($file->getClientMimeType());
     $media->setSize($file->getClientSize());
     return $media;
 }
Exemplo n.º 9
0
 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         $fileName = $this->getNewUniqueFilename($fileName);
     }
     return $this->model->create(['filename' => $fileName, 'path' => config('asgard.media.config.files-path') . "{$fileName}", 'extension' => substr(strrchr($fileName, "."), 1), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize(), 'folder_id' => 0]);
 }
 /**
  * Check if all chunks of a file being uploaded have been received
  * If yes, return the name of the reassembled temporary file
  *
  * @param UploadedFile $uploadedFile
  *
  * @return UploadedFile|null
  */
 public function getFileFromChunks(UploadedFile $uploadedFile)
 {
     $filename = time() . '-' . $uploadedFile->getClientOriginalName();
     $path = $this->tmpDir . DIRECTORY_SEPARATOR . $filename;
     if (FlowBasic::save($path, $this->tmpDir)) {
         return new UploadedFile($path, $uploadedFile->getClientOriginalName(), $uploadedFile->getClientMimeType());
     }
     return null;
 }
Exemplo n.º 11
0
 /**
  * Setup image file
  *
  * @param UploadedFile $file
  * @param string       $style_guide
  */
 public function setupFile(UploadedFile $file, $style_guide = null)
 {
     $this->_source = $file;
     $this->setFileExtension($file->getClientOriginalExtension());
     $this->setFileNameAttribute($file->getClientOriginalName());
     $this->setMimeTypeAttribute($file->getClientMimeType());
     $this->setFileSizeAttribute($file->getSize());
     if (!empty($style_guide)) {
         $this->setStyleGuideName($style_guide);
     }
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function save(UploadedFile $file, $dir)
 {
     $media = new Media();
     $media->setName($file->getClientOriginalName());
     $media->setExtension($file->guessClientExtension());
     $media->setMime($file->getClientMimeType());
     $media->setSize($file->getClientSize());
     $this->_em->persist($media);
     $this->_em->flush();
     return $media;
 }
 /**
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  *
  * @return array
  */
 private function createDbData(UploadedFile $file, $completedPath, $propertyId)
 {
     $data = [];
     $type = $file->getClientMimeType();
     $fileName = $file->getClientOriginalName();
     $data["type"] = $type;
     $data["path"] = $completedPath;
     // TODO: need to fix for different storage location
     $data["link"] = "/files/" . urlencode(str_replace(public_path() . "/files/", "", $completedPath));
     $data["fileName"] = $fileName;
     $data["property_id"] = $propertyId;
     return $data;
 }
Exemplo n.º 14
0
 /**
  * Build a \Torann\MediaSort\File\UploadedFile object from
  * a Symfony\Component\HttpFoundation\File\UploadedFile object.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  *
  * @return \Torann\MediaSort\File\UploadedFile
  * @throws \Torann\MediaSort\Exceptions\FileException
  */
 protected function createFromObject(SymfonyUploadedFile $file)
 {
     $path = $file->getPathname();
     $originalName = $file->getClientOriginalName();
     $mimeType = $file->getClientMimeType();
     $size = $file->getClientSize();
     $error = $file->getError();
     $uploadFile = new UploadedFile($path, $originalName, $mimeType, $size, $error);
     if (!$uploadFile->isValid()) {
         throw new FileException($uploadFile->getErrorMessage($uploadFile->getError()));
     }
     return $uploadFile;
 }
Exemplo n.º 15
0
 /**
  * Upload new attachment
  *
  * @param UploadedFile $file
  * @param string       $descriptionText
  * @param Language     $language
  * @param array        $attributes
  * @param Attachment   $attachment
  *
  * @return Attachment
  */
 public function upload(UploadedFile $file, $descriptionText, Language $language, array $attributes, Attachment $attachment = null)
 {
     $filesystem = new Filesystem();
     $filesize = $file->getClientSize();
     if ($filesize == false) {
         throw new FileException('File size is not valid');
     }
     if (!file_exists($this->config['file_directory']) || !is_writable($this->config['file_directory'])) {
         throw new FileException('Directory ' . $this->config['file_directory'] . ' is not writable');
     }
     if (!is_null($attachment)) {
         if ($filesystem->exists($this->getStorageLocation($attachment))) {
             $filesystem->remove($this->getStorageLocation($attachment));
         }
         if ($descriptionText != $attachment->getDescription()->getTranslationText()) {
             $nextTranslationPhraseId = $this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextTranslationPhraseId();
             $description = new Translation($nextTranslationPhraseId);
             $description->setLanguage($language);
             $description->setTranslationText($descriptionText);
             $this->em->persist($description);
         }
         unset($attributes['description']);
     } else {
         $attachment = new Attachment();
         $nextTranslationPhraseId = $this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextTranslationPhraseId();
         $description = new Translation($nextTranslationPhraseId);
         $description->setLanguage($language);
         $description->setTranslationText($descriptionText);
         unset($attributes['description']);
         $attachment->setCreated(new \DateTime());
         $this->em->persist($description);
         $this->em->persist($attachment);
     }
     $attributes = array_merge(array('language' => $language, 'name' => $file->getClientOriginalName(), 'extension' => $file->getClientOriginalExtension(), 'mimeType' => $file->getClientMimeType(), 'contentDisposition' => Attachment::CONTENT_DISPOSITION, 'sizeInBytes' => $file->getClientSize(), 'description' => $description), $attributes);
     $this->fillAttachment($attachment, $attributes);
     if (is_null($attributes['name'])) {
         $attachment->setName($file->getClientOriginalName());
     }
     $this->em->flush();
     $target = $this->makeDirectories($attachment);
     try {
         $file->move($target, $this->getFileName($attachment));
         $filesystem->chmod($target . '/' . $this->getFileName($attachment), 0644);
     } catch (\Exceptiom $e) {
         $filesystem->remove($target);
         $this->em->remove($attachment);
         $this->em->flush();
         throw new \Exception($e->getMessage(), $e->getCode());
     }
     return $attachment;
 }
Exemplo n.º 16
0
 /**
  * Upload method
  *
  * @param UploadedFile $file file to upload
  *
  * @return string
  * @throws \InvalidArgumentException
  */
 public function upload(UploadedFile $file)
 {
     $fileMimeType = $file->getClientMimeType();
     if ($this->allowedTypes && !in_array($fileMimeType, $this->allowedTypes)) {
         throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $fileMimeType));
     }
     $filename = $this->generateNameByOriginal($file->getClientOriginalName());
     $adapter = $this->filesystem->getAdapter();
     if (!$adapter instanceof Local) {
         $adapter->setMetadata($filename, ['contentType' => $fileMimeType]);
     }
     $adapter->write($filename, file_get_contents($file->getPathname()));
     return $filename;
 }
Exemplo n.º 17
0
 /**
  * PrePersist()
  */
 public function preUpload()
 {
     if (null === $this->getFile()) {
         return;
     }
     try {
         $this->setMimeType($this->file->getMimetype());
     } catch (FileNotFoundException $e) {
         $this->setMimeType($this->file->getClientMimeType());
     }
     // set the path property to the filename where you'ved saved the file
     $filename = $this->sanitise($this->file->getClientOriginalName());
     $this->setFilename($filename);
 }
Exemplo n.º 18
0
 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         $fileName = $this->getNewUniqueFilename($fileName);
     }
     $data = ['filename' => $fileName, 'path' => config('asgard.media.config.files-path') . "{$fileName}", 'extension' => substr(strrchr($fileName, "."), 1), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize(), 'folder_id' => 0];
     if (is_module_enabled('Site')) {
         $siteId = Site::id();
         $data['site_id'] = $siteId;
         $data['path'] = config('asgard.media.config.files-path') . '/' . Site::current()->slug . "/{$fileName}";
     }
     return $this->model->create($data);
 }
Exemplo n.º 19
0
 public function upload(UploadedFile $uploadedFile)
 {
     $name = $this->generateUniqueName();
     $directory = $this->getDirectory($name);
     $ext = strtolower($uploadedFile->getClientOriginalExtension());
     $image = Image::register($name, $name . '.' . $ext);
     $image->setDirectory($directory);
     $image->setMime($uploadedFile->getClientMimeType());
     $image->setTitle($uploadedFile->getClientOriginalName());
     $this->imageRepo->add($image);
     $fys_img = InterventionImage::make($uploadedFile);
     //TODO: FULL PATH INFO FROM IMAGE
     //ie /blablabla/public/upload/4/e/3/4/4e3409834098938409834.jpg
     $fys_img->save($this->fullPath($img));
     return $image;
 }
Exemplo n.º 20
0
 protected function checkFile(UploadedFile $file)
 {
     $mime = $file->getClientMimeType();
     $info = array('name' => $file->getClientOriginalName(), 'size' => $file->getClientSize(), 'mime' => $mime, 'extension' => $file->getClientOriginalExtension(), 'type' => $mime, 'error' => '');
     if ($file->isValid()) {
         if (!$info['type']) {
             $info['status'] = 9;
             $info['error'] = '不支持的文件类型';
         } else {
             $info['status'] = UPLOAD_ERR_OK;
         }
     } else {
         $info['status'] = $file->getError();
         $info['error'] = $file->getErrorMessage();
     }
     return $info;
 }
Exemplo n.º 21
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $rootPath = $this->container->get('kernel')->getRootDir() . '/../web/themes/wellcommerce/assets/prod/';
     $uploader = $this->container->get('media.manager.admin');
     $uploadPath = $uploader->getUploadRootDir('images');
     $filesystem = $this->container->get('filesystem');
     foreach (self::$samples as $photo) {
         $image = new UploadedFile($rootPath . $photo, $photo, 'image/jpeg', filesize($rootPath . $photo));
         $media = new Media();
         $media->setName($image->getClientOriginalName());
         $media->setExtension($image->guessClientExtension());
         $media->setMime($image->getClientMimeType());
         $media->setSize($image->getClientSize());
         $manager->persist($media);
         $filesystem->copy($rootPath . $photo, $uploadPath . '/' . $media->getPath());
         $this->setReference('photo_' . $photo, $media);
     }
     $manager->flush();
 }
Exemplo n.º 22
0
 public function upload(UploadedFile $file, $dir) : MediaInterface
 {
     if (!$file->isValid()) {
         throw new InvalidMediaException('Passed file object is not valid');
     }
     /** @var MediaInterface $media */
     $media = $this->manager->initResource();
     $media->setName($file->getClientOriginalName());
     $media->setExtension($file->guessClientExtension());
     $media->setMime($file->getClientMimeType());
     $media->setSize($file->getClientSize());
     $errors = $this->validatorHelper->validate($media);
     if (0 !== count($errors)) {
         throw new InvalidMediaException($errors);
     }
     $this->manager->createResource($media);
     $file->move($this->getUploadDir($dir), $media->getPath());
     return $media;
 }
Exemplo n.º 23
0
 /**
  * Upload image and create entity
  *
  * @param UploadedFile $file
  * @param array        $attributes
  *
  * @return Local
  */
 public function upload(UploadedFile $file, array $attributes)
 {
     $filesystem = new Filesystem();
     $imagine = new Imagine();
     $errors = array();
     $mimeType = $file->getClientMimeType();
     if (!in_array($mimeType, $this->supportedTypes)) {
         $errors[] = $this->translator->trans('ads.error.unsupportedType', array('%type%' => $mimeType));
     }
     if (!file_exists($this->config['image_path']) || !is_writable($this->config['image_path'])) {
         $errors[] = $this->translator->trans('ads.error.notwritable', array('%dir%' => $this->config['image_dir']));
     }
     if (!file_exists($this->config['thumbnail_path']) || !is_writable($this->config['thumbnail_path'])) {
         $errors[] = $this->translator->trans('ads.error.notwritable', array('%dir%' => $this->config['thumbnail_dir']));
     }
     if (!empty($errors)) {
         return $errors;
     }
     $attributes = array_merge(array('content_type' => $mimeType), $attributes);
     $image = new Image($file->getClientOriginalName());
     $this->orm->persist($image);
     $this->fillImage($image, $attributes);
     $this->orm->flush();
     $imagePath = $this->generateImagePath($image->getId(), $file->getClientOriginalExtension());
     $thumbnailPath = $this->generateThumbnailPath($image->getId(), $file->getClientOriginalExtension());
     $image->setBasename($this->generateImagePath($image->getId(), $file->getClientOriginalExtension(), true));
     $image->setThumbnailPath($this->generateThumbnailPath($image->getId(), $file->getClientOriginalExtension(), true));
     $this->orm->flush();
     try {
         $file->move($this->config['image_path'], $this->generateImagePath($image->getId(), $file->getClientOriginalExtension(), true));
         $filesystem->chmod($imagePath, 0644);
         $imagine->open($imagePath)->resize(new Box($this->config['thumbnail_max_size'], $this->config['thumbnail_max_size']))->save($thumbnailPath, array());
         $filesystem->chmod($thumbnailPath, 0644);
     } catch (\Exceptiom $e) {
         $filesystem->remove($imagePath);
         $filesystem->remove($thumbnailPath);
         $this->orm->remove($image);
         $this->orm->flush();
         return array($e->getMessage());
     }
     return $image;
 }
Exemplo n.º 24
0
 /**
  * Upload archivo
  */
 public function upload($directorio, $nombre, $visible = false)
 {
     if (null === $this->file) {
         return false;
     }
     $targetDir = $this->getUploadRootDir() . DIRECTORY_SEPARATOR . $directorio;
     $extension = $this->getExtensionOriginal();
     $nombreArray = explode('.', $nombre);
     $extNombre = '.' . $nombreArray[count($nombreArray) - 1];
     if ($extNombre == $extension) {
         array_pop($nombreArray);
     }
     $slugify = new Slugify();
     $nombre = $slugify->slugify(implode('.', $nombreArray)) . $extension;
     $this->file->move($targetDir, $nombre);
     $this->setRuta($directorio . DIRECTORY_SEPARATOR . $nombre);
     $this->setMimeType($this->file->getClientMimeType());
     $this->visible = $visible;
     return $nombre;
 }
 /**
  * Upload a file and save it in storage.
  *
  * @param UploadedFile $uploadedFile
  * @param string       $directory
  * @return array
  */
 static function upload(UploadedFile $uploadedFile, $directory)
 {
     $extension = $uploadedFile->getClientOriginalExtension();
     if ($extension != '') {
         // get the filename
         $filename = $uploadedFile->getClientOriginalName();
         // get the name of the file and the mime type
         $name = substr($filename, 0, strrpos($filename, '.'));
         $mime = $uploadedFile->getClientMimeType();
         // clean up the filename
         $filename = FileHelper::serializeFilename($filename, true);
         // make sure the filename is unique
         $filename = FileHelper::incrementFilename($filename, $directory);
         // the full path to the file
         $filepath = $directory . $filename;
         // save new file to storage
         Storage::put($filepath, File::get($uploadedFile));
         return array('name' => $name, 'mime' => $mime, 'filename' => $filename);
     }
 }
Exemplo n.º 26
0
 /**
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param \HorseStories\Models\Horses\Horse $horse
  * @param bool $profile
  * @return \HorseStories\Models\Pictures\Picture
  */
 public function uploadPicture($file, $horse, $profile = false)
 {
     $extension = $file->getClientOriginalExtension();
     $path = '/uploads/pictures/' . $horse->id;
     $fileName = str_random(12);
     $pathToFile = storage_path() . '/app' . $path . '/' . $fileName . '.' . $extension;
     $picture = new Picture();
     $picture->path = $fileName . '.' . $extension;
     $picture->horse_id = $horse->id;
     $picture->mime = $file->getClientMimeType();
     $picture->original_name = $file->getClientOriginalName();
     $picture->profile_pic = $profile;
     $picture->save();
     if (!file_exists(storage_path() . $path)) {
         $this->file->makeDirectory($path);
     }
     $this->image->make($file->getrealpath())->resize(null, 350, function ($constraints) {
         $constraints->aspectRatio();
     })->save($pathToFile);
     return $picture;
 }
Exemplo n.º 27
0
 /**
  * Handle the file upload. Returns the array on success, or false
  * on failure.
  *
  * @param  \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param  String                                              $path where to upload file
  * @return array|bool
  */
 public function handle(UploadedFile $file, $path = 'uploads')
 {
     $input = [];
     $fileName = str_slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
     $fileName = preg_replace('#([0-9_]+)x([0-9_]+)#', "\$1-\$2", $fileName);
     $input['path'] = $path;
     $input['extension'] = '.' . $file->getClientOriginalExtension();
     $input['filesize'] = $file->getClientSize();
     $input['mimetype'] = $file->getClientMimeType();
     $input['filename'] = $fileName . $input['extension'];
     $filecounter = 1;
     while (file_exists($input['path'] . '/' . $input['filename'])) {
         $input['filename'] = $fileName . '_' . $filecounter++ . $input['extension'];
     }
     try {
         $file->move($input['path'], $input['filename']);
         return $input;
     } catch (FileException $e) {
         \Log::error($e->getmessage());
         return false;
     }
 }
Exemplo n.º 28
0
 public function boot()
 {
     intercept('XeStorage@upload', 'orientator.orientate', function ($target, $uploaded, $path, $name = null, $disk = null, $user = null) {
         /** @var UploadedFile $uploaded */
         if ($uploaded->isValid()) {
             $mime = $uploaded->getMimeType();
             /** @var \Xpressengine\Media\Handlers\ImageHandler $imageHandler */
             $imageHandler = app('xe.media')->getHandler(Media::TYPE_IMAGE);
             // todo: 모바일 판단여부 적용 or 무시 (ex. app('request')->isMobile())
             if ($imageHandler->isAvailable($mime)) {
                 $manager = new ImageManager();
                 $image = $manager->make($uploaded);
                 if (isset($image->exif()['Orientation'])) {
                     $content = $image->orientate()->encode()->getEncoded();
                     file_put_contents($uploaded->getPathname(), $content);
                     $uploaded = new UploadedFile($uploaded->getPathname(), $uploaded->getClientOriginalName(), $uploaded->getClientMimeType(), strlen($content));
                 }
             }
         }
         return $target($uploaded, $path, $name, $disk, $user);
     });
 }
Exemplo n.º 29
0
 /**
  * Creates a PSR-7 UploadedFile instance from a Symfony one.
  *
  * @param UploadedFile $symfonyUploadedFile
  *
  * @return UploadedFileInterface
  */
 private function createUploadedFile(UploadedFile $symfonyUploadedFile)
 {
     return new DiactorosUploadedFile($symfonyUploadedFile->getRealPath(), $symfonyUploadedFile->getSize(), $symfonyUploadedFile->getError(), $symfonyUploadedFile->getClientOriginalName(), $symfonyUploadedFile->getClientMimeType());
 }
 public function testFileUploadsWithUnknownMimeType()
 {
     $file = new UploadedFile(__DIR__ . '/Fixtures/.unknownextension', 'original.gif', null, filesize(__DIR__ . '/Fixtures/.unknownextension'), UPLOAD_ERR_OK);
     $this->assertEquals('application/octet-stream', $file->getClientMimeType());
 }