当前位置: 首页>>代码示例>>PHP>>正文


PHP UploadedFile::getClientOriginalName方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getClientOriginalName方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getClientOriginalName方法的具体用法?PHP UploadedFile::getClientOriginalName怎么用?PHP UploadedFile::getClientOriginalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\File\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::getClientOriginalName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleUploadedFile

 /**
  * Handles an uploaded file by putting it in the $targetDir.
  * 
  * @param UploadedFile $uploadedFile File object that has been uploaded - usually taken from Request object.
  * @param string $targetDir [optional] Where to (relatively to the storage root dir) put the file?
  * @param array $allowed [optional] What files are allowed? If not matching then will throw exception.
  * @param int $maxFileSize [optional] What is the maximum allowed file size for this file?
  * @return File
  */
 public function handleUploadedFile(UploadedFile $uploadedFile, $targetDir = '/', array $allowed = array(), $maxFileSize = 0)
 {
     array_walk($allowed, function ($ext) {
         return strtolower($ext);
     });
     $targetDir = trim($targetDir, '/');
     $targetDir = $this->path . $targetDir . (empty($targetDir) ? '' : '/');
     $filenameElements = explode('.', $uploadedFile->getClientOriginalName());
     $extension = array_pop($filenameElements);
     $extension = strtolower($extension);
     $filename = implode('.', $filenameElements);
     $targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
     $targetPath = $targetDir . $targetName;
     // create unique file name
     while (file_exists($targetPath)) {
         $targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
         $targetPath = $targetDir . $targetName;
     }
     // basic check for allowed type
     if (!empty($allowed) && !in_array($extension, $allowed)) {
         throw new FileException('The uploaded file is not of a valid type (allowed: ' . implode(', ', $allowed) . ').');
     }
     // basic check for max allowed size
     if ($maxFileSize && $uploadedFile->getSize() > $maxFileSize) {
         throw new FileException('The uploaded file is too big (max allowed size is ' . StringUtils::bytesToString($maxFileSize) . ').');
     }
     try {
         $movedFile = $uploadedFile->move(rtrim($targetDir, '/'), $targetName);
     } catch (SfFileException $e) {
         // if exception thrown then convert it to our exception
         throw new FileException($e->getMessage(), $e->getCode());
     }
     $file = $this->convertSfFileToStorageFile($movedFile);
     return $file;
 }
开发者ID:splot,项目名称:framework-extra-module,代码行数:44,代码来源:SimpleStorage.php

示例2: orientate

 /**
  * 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());
 }
开发者ID:AkibaTech,项目名称:files-module,代码行数:39,代码来源:FileRotator.php

示例3: convertFieldValueFromForm

 /**
  * {@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());
 }
开发者ID:eab-dev,项目名称:NetgenEzFormsBundle,代码行数:12,代码来源:Image.php

示例4: handleUpload

 /**
  * @param UploadedFile|null $uploadedFile
  * @param array $options
  * @return AssetFile
  */
 public function handleUpload(UploadedFile $uploadedFile = null, array $options = [])
 {
     $resolver = new OptionsResolver();
     $resolver->setDefaults(['type' => null, 'fallbackType' => null, 'targetUri' => null])->setAllowedTypes(['type' => ['string', 'null'], 'fallbackType' => ['int', 'null'], 'targetUri' => ['string', 'null']])->setAllowedValues(['type' => ['image', 'audio', 'file', null]]);
     $options = $resolver->resolve($options);
     if (!$uploadedFile instanceof UploadedFile || !$uploadedFile->isValid() || !($assetFile = new AssetFile($uploadedFile, null, $options['fallbackType'])) || $assetFile->getType() === null) {
         throw new \RuntimeException('Invalid uploaded file');
     }
     $assetFile->setOriginalName($uploadedFile->getClientOriginalName());
     if ($options['type'] !== null) {
         $this->validateAssetFileType($assetFile, $options['type']);
     }
     if ($options['targetUri'] !== null) {
         $uploadsDir = $this->assetsResolver->uriToPath($options['targetUri']);
     } else {
         $uploadsDir = $this->assetsResolver->assetPath($assetFile->getType());
     }
     $tempFile = $uploadedFile->move($uploadsDir, $this->getTargetFileName($uploadedFile->getClientOriginalName(), $uploadsDir));
     $assetFile->setFile($tempFile);
     $uri = $this->assetsResolver->pathToUri($assetFile->getFile()->getPathname());
     if ($uri === null) {
         throw new \RuntimeException('Unable to retrieve uploaded file uri');
     }
     $assetFile->setUri($uri);
     return $assetFile;
 }
开发者ID:harentius,项目名称:blog-bundle,代码行数:31,代码来源:Manager.php

示例5: createVersionFromFile

 /**
  * @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;
 }
开发者ID:robbytaylor,项目名称:boom-core,代码行数:14,代码来源:Asset.php

示例6: moveFile

 private function moveFile(UploadedFile $file, $id)
 {
     $destinationPath = $this->getDestinationPath() . '/' . $this->getPathById($id);
     if ($file->move($destinationPath, $file->getClientOriginalName())) {
         return $this->getPathById($id) . '/' . $file->getClientOriginalName();
     }
     return '';
 }
开发者ID:moszkva,项目名称:fileuploader,代码行数:8,代码来源:Manager.php

示例7: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     if (null === $this->file) {
         return;
     }
     $this->url = $this->file->guessExtension();
     $this->alt = $this->file->getClientOriginalName();
 }
开发者ID:AlexandreRozier,项目名称:Symfony,代码行数:12,代码来源:Image.php

示例8: uniqueName

 /**
  * For files, we won't generate a very random name,
  * so we can easily.
  *
  *
  */
 protected function uniqueName()
 {
     $filename = $this->file->getClientOriginalName();
     $filename = str_replace(' ', '-', $filename);
     $pieces = explode('.', $filename);
     array_pop($pieces);
     return implode('.', $pieces);
 }
开发者ID:jaffle-be,项目名称:framework,代码行数:14,代码来源:UploadNewFile.php

示例9: fileName

 /**
  * Get the file name for the photo
  *
  * @return string
  */
 public function fileName()
 {
     if (!is_null($this->name) && $this->name) {
         return $this->name;
     }
     $name = sha1($this->file->getClientOriginalName() . '-' . microtime());
     $extension = $this->file->getClientOriginalExtension();
     return "{$name}.{$extension}";
 }
开发者ID:productionEA,项目名称:pockeyt-api,代码行数:14,代码来源:Photo.php

示例10: upload

 public function upload()
 {
     if (null === $this->file) {
         return;
     }
     $name = $this->file->getClientOriginalName();
     $this->file->move($this->getUploadRootDir(), $name);
     $this->url = $name;
 }
开发者ID:bamper,项目名称:webstore,代码行数:9,代码来源:UploadFile.php

示例11: getFileFromChunks

 /**
  * 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;
 }
开发者ID:open-orchestra,项目名称:open-orchestra-media-admin-bundle,代码行数:17,代码来源:SaveMediaManager.php

示例12: makeFileRecord

 /**
  * 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;
 }
开发者ID:grlf,项目名称:laravel-portal-template,代码行数:16,代码来源:StoreFileableFiles.php

示例13: run

 public function run(UploadedFile $file, MediaProvider $media)
 {
     $media->ext = $file->getClientOriginalExtension();
     $media->path = $file->getPath();
     // by default /tmp
     $media->file = $file->getClientOriginalName();
     $media->meta = empty($media->meta) ? [] : $media->meta;
     $media->sizes = empty($media->sizes) ? [] : $media->sizes;
     $media->caption = $file->getClientOriginalName();
     $media->alt = $file->getClientOriginalName();
 }
开发者ID:typerocket,项目名称:laravel,代码行数:11,代码来源:Setup.php

示例14: preUpload

 /**
  * @ORM\PrePersist()
  * @ORM\PreUpdate()
  */
 public function preUpload()
 {
     // Si jamais il n'y a pas de fichier (champ facultatif)
     if (null === $this->file) {
         return;
     }
     // Le nom du fichier est son id, on doit juste stocker �galement son extension
     // Pour faire propre, on devrait renommer cet attribut en � extension �, plut�t que � extension �
     $this->extension = $this->file->guessExtension();
     // Et on g�n�re l'attribut alt de la balise <img>, � la valeur du nom du fichier sur le PC de l'internaute
     $this->alt = $this->file->getClientOriginalName();
 }
开发者ID:messi1983,项目名称:messi-repo,代码行数:16,代码来源:Image.php

示例15: playTorrentFileAction

 public function playTorrentFileAction(Request $request)
 {
     $file = $_FILES['torrentFile'];
     $type = $_POST['torrentFileType'];
     $filename = $_POST['torrentFileName'];
     $uploadedFile = new UploadedFile($file['tmp_name'], $filename, $type);
     $moveTo = $this->get('kernel')->getRootDir() . '/cache/' . $this->get('kernel')->getEnvironment();
     $uploadedFile->move($moveTo, $uploadedFile->getClientOriginalName());
     $streamerService = $this->get('homesoft_torrent_streamer.torrent_streamer');
     $response = array('status' => true, 'url' => $streamerService->startStreamer($moveTo . '/' . $uploadedFile->getClientOriginalName()));
     return new JsonResponse($response);
 }
开发者ID:elpiafo3,项目名称:Torrent-Streamer,代码行数:12,代码来源:DefaultController.php


注:本文中的Symfony\Component\HttpFoundation\File\UploadedFile::getClientOriginalName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。