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


PHP File::getClientOriginalName方法代码示例

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


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

示例1: getName

 /**
  * Get original name of file.
  *
  * @return string
  */
 public function getName()
 {
     if ($this->file instanceof UploadedFile) {
         return $this->file->getClientOriginalName();
     }
     return $this->file->getFilename();
 }
开发者ID:Vooodoo,项目名称:MediaBundle,代码行数:12,代码来源:FileInfo.php

示例2: preUpload

 public function preUpload()
 {
     if (null !== $this->file) {
         // do whatever you want to generate a unique name
         $this->file_name = $this->file->getClientOriginalName();
         $this->charte_file = uniqid() . '.' . $this->file->guessExtension();
     }
 }
开发者ID:luciemannechez,项目名称:projet-intranet_hopital,代码行数:8,代码来源:Charte.php

示例3: upload

 /**
  * @throws FileException
  */
 public function upload()
 {
     if ($this->file instanceof File) {
         $name = sha1($this->file->getClientOriginalName() . uniqid() . getrandmax()) . '.' . $this->file->guessExtension();
         $this->file->move($this->getWeb() . $this->folder, $name);
         $this->file = $name;
     } else {
         throw new FileException('It must be a Symfony\\Component\\HttpFoundation\\File\\File instance');
     }
 }
开发者ID:radmar,项目名称:RedactorBundle,代码行数:13,代码来源:Resource.php

示例4: setFileAttribute

 public function setFileAttribute(\Symfony\Component\HttpFoundation\File\File $file)
 {
     $this->attributes['file'] = $file;
     $this->original_name = $file instanceof UploadedFile ? $file->getClientOriginalName() : $file->getFilename();
     $this->size = $file->getSize();
     $this->content_type = $file->getMimeType();
 }
开发者ID:AniartUA,项目名称:crm,代码行数:7,代码来源:File.php

示例5: __construct

 /**
  * Constructor.
  *
  * @param File $file A File instance
  */
 public function __construct(File $file)
 {
     if ($file instanceof UploadedFile) {
         parent::__construct($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true);
     } else {
         parent::__construct($file->getPathname(), $file->getBasename(), $file->getMimeType(), $file->getSize(), 0, true);
     }
 }
开发者ID:sfblaauw,项目名称:pulsar-uploader,代码行数:13,代码来源:FilesystemFile.php

示例6: saveFile

 /**
  * Save uploaded file without validation
  *
  * @param File $file
  * @param string $newLocation
  * @param string $newName
  * @throws FileException
  * @return File
  */
 protected function saveFile(File $file, $newLocation, $newName = "")
 {
     $name = $file->getClientOriginalName();
     if ($newName) {
         $name = $newName;
     }
     return $file->move($this->createFolderIfNotExist($newLocation), $this->getUniqueFileName($name, $newLocation));
 }
开发者ID:LazyNewbie,项目名称:boilerplate,代码行数:17,代码来源:FilesTrait.php

示例7: storeFileInPath

 public function storeFileInPath($path, File $file, $name = null)
 {
     $filename = $name ? $name : $file->getClientOriginalName();
     for ($i = 2; file_exists($path . $filename); $i++) {
         $filename = $i . '_' . $filename;
     }
     $file->move($path, $filename);
     return $filename;
 }
开发者ID:joadr,项目名称:cms,代码行数:9,代码来源:FilesHelper.php

示例8: setFile

 /**
  * @param File|null $file
  */
 public function setFile(File $file = null)
 {
     $this->file = $file;
     $this->fileMimeType = $this->file->getMimeType();
     $this->fileSize = $this->file->getSize();
     if ($this->file instanceof UploadedFile) {
         $this->fileOriginalName = $this->file->getClientOriginalName();
     }
     //        dump($this);
 }
开发者ID:Koc,项目名称:stfalcon-test-task,代码行数:13,代码来源:Photo.php

示例9: create

 /**
  * {@inheritDoc}
  */
 public function create(File $file)
 {
     $mc = $this->getMediaClass();
     $baseFile = new $mc();
     $baseFile->setPath($file->getPathname());
     $baseFile->setName($file->getClientOriginalName());
     if ($baseFile instanceof BaseFile) {
         $baseFile->setCreatedAt(new \DateTime());
         $baseFile->setSize($file->getSize());
         $baseFile->setContentType($file->getMimeType());
     }
     return $baseFile;
 }
开发者ID:P3PO,项目名称:VlabsMediaBundle,代码行数:16,代码来源:AbstractHandler.php

示例10: validateFileExtension

 protected function validateFileExtension(File $file, $extensions)
 {
     if ($file instanceof UploadedFile) {
         $filename = $file->getClientOriginalName();
     } else {
         $filename = $file->getFilename();
     }
     $errors = array();
     $regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
     if (!preg_match($regex, $filename)) {
         $errors[] = "只允许上传以下扩展名的文件:" . $extensions;
     }
     return $errors;
 }
开发者ID:robert-li-2015,项目名称:EduSoho,代码行数:14,代码来源:FileServiceImpl.php

示例11: getNormalizedFilename

 /**
  * @param File $file
  * @return string
  */
 protected function getNormalizedFilename(File $file)
 {
     if ($file instanceof UploadedFile) {
         $originalFilename = $file->getClientOriginalName();
         $size = $file->getClientSize();
     } else {
         $originalFilename = $file->getFilename();
         $size = $file->getSize();
     }
     $name = preg_replace(self::REGEX_FILENAME_EXT, '', $originalFilename);
     $name = preg_replace(self::REGEX_INVALID_FILENAME_CHARS, '_', $name);
     $hash = substr(sha1(json_encode(array(time(), $name, $size))), 0, 7);
     $ext = $file->getExtension();
     if (!$ext) {
         $ext = explode('.', $originalFilename);
         $ext = end($ext);
     }
     $filename = sprintf('%s_%s.%s', $name, $hash, $ext);
     return $filename;
 }
开发者ID:Kyoushu,项目名称:CommonBundle,代码行数:24,代码来源:UploadHandler.php

示例12: uploadImage

 /**
  * Enregistre l'icône sur le disque.
  *
  * @return void
  */
 protected function uploadImage()
 {
     $this->deleteImage();
     $this->miniature = null;
     $fichier = new Fichier($this->imageFile->getRealPath());
     $this->image = $this->imageFile->getClientOriginalName();
     $this->dossier = $this->guessSousDossier();
     $fichier->move($this->getImageUploadDir() . DIRECTORY_SEPARATOR . $this->image, false);
     $image = new Image($fichier->getChemin());
     $image->setNomMinifie($this->getTitle(), '-', true, 128);
     $this->image = $image->getNom();
     if ($image->getLargeur() >= $image->getHauteur() && $image->getLargeur() > $this->getLargeurMaximale()) {
         $image->redimensionne($this->getLargeurMaximale(), null, true);
     } elseif ($image->getLargeur() < $image->getHauteur() && $image->getHauteur() > $this->getHauteurMaximale()) {
         $image->redimensionne(null, $this->getHauteurMaximale(), true);
     }
     $this->largeur = $image->getLargeur();
     $this->hauteur = $image->getHauteur();
     $this->setImageFile(null);
 }
开发者ID:lyssal,项目名称:collection-bundle,代码行数:25,代码来源:Illustration.php

示例13: getTargetFileName

 /**
  * Get the full target name for the uploaded file.
  *
  * @return string
  */
 protected function getTargetFileName()
 {
     if ($this->final) {
         return $this->fileName;
     }
     // Create a unique filename with a simple pattern
     $originalName = $this->file->getClientOriginalName();
     $extension = $this->file->guessExtension() ?: pathinfo($originalName, PATHINFO_EXTENSION);
     $pattern = $this->getTargetFileNamePattern();
     $fileName = sprintf($pattern, pathinfo($originalName, PATHINFO_FILENAME), $extension);
     $this->fullPath = $this->getTargetFileDirectory() . DIRECTORY_SEPARATOR . $fileName;
     $i = 1;
     while (file_exists($this->fullPath)) {
         $fileName = sprintf($pattern, pathinfo($originalName, PATHINFO_FILENAME) . "({$i})", $extension);
         $this->fullPath = $this->getTargetFileDirectory() . DIRECTORY_SEPARATOR . $fileName;
         $i++;
     }
     $this->app['logger.system']->debug("[BoltForms] Setting uploaded file '{$originalName}' to use the name '{$fileName}'.", array('event' => 'extensions'));
     $this->final = true;
     return $this->fileName = $fileName;
 }
开发者ID:evertalbers,项目名称:bolt-extension-boltforms,代码行数:26,代码来源:FileUpload.php

示例14: preUpload

 public function preUpload()
 {
     if (null !== $this->getFile()) {
         // set the asset title as original file name if title is missing
         if (null === $this->getTitle()) {
             $this->setTitle($this->file->getClientOriginalName());
         }
         $filename = sha1(uniqid(mt_rand(), true));
         $extension = $this->getFile()->guessExtension();
         if (empty($extension)) {
             //get it from the original name
             $extension = pathinfo($this->originalFileName, PATHINFO_EXTENSION);
         }
         $this->path = $filename . '.' . $extension;
     } elseif ($this->getStorageLocation() == 'remote' && $this->getRemotePath() !== null) {
         $fileName = basename($this->getRemotePath());
         $this->setOriginalFileName($fileName);
         // set the asset title as original file name if title is missing
         if (null === $this->getTitle()) {
             $this->setTitle($fileName);
         }
     }
 }
开发者ID:Jandersolutions,项目名称:mautic,代码行数:23,代码来源:Asset.php

示例15: setFile

 /**
  * Sets file.
  *
  * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
  */
 public function setFile(File $file = null)
 {
     $this->file = $file;
     if ($file) {
         // It is required that at least one field changes if you are using doctrine
         // otherwise the event listeners won't be called and the file is lost
         $this->updatedAt = new \DateTime('now');
         $this->fileType = strtoupper($file->getExtension());
         $this->size = $file->getSize();
         if ($file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
             $this->originalName = $file->getClientOriginalName();
             if ($this->isNoname) {
                 $this->name = $this->originalName;
             }
         }
     }
 }
开发者ID:anhpha,项目名称:reports,代码行数:22,代码来源:Document.php


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