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


PHP UploadedFile::getFilename方法代码示例

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


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

示例1: validate

 /**
  * @param UploadedFile $file
  * @param array        $methods
  *
  * @return mixed|void
  *
  * @throws InvalidFileTypeException
  * @throws InvalidFileException
  * @throws UploadFileNotSetException
  * @throws MaxFileSizeExceededException
  */
 public function validate(UploadedFile $file, $methods = [self::VALIDATOR_FILE_SET, self::VALIDATOR_FILE_ERRORS, self::VALIDATOR_BLOCK_FILE_TYPES, self::VALIDATOR_MAX_FILE_SIZE])
 {
     if (in_array(self::VALIDATOR_FILE_ERRORS, $methods) && $file->getError() > 0) {
         throw new InvalidFileException(sprintf('The file upload had an error("%s: %s")', $file->getError(), $file->getErrorMessage()));
     }
     if (in_array(self::VALIDATOR_FILE_SET, $methods) && $file->getFilename() == '') {
         throw new UploadFileNotSetException(sprintf('No file "%s" was set', $file->getFilename()));
     }
     if (in_array(self::VALIDATOR_BLOCK_FILE_TYPES, $methods) && in_array($file->getMimeType(), $this->blockedMimeTypes)) {
         throw new InvalidFileTypeException(sprintf('The file type "%s" was blocked', $file->getMimeType()));
     }
     if (in_array(self::VALIDATOR_MAX_FILE_SIZE, $methods) && $this->maxFileSize !== null && $file->getSize() >= $this->maxFileSize) {
         throw new MaxFileSizeExceededException(sprintf('File "%s" exceeds the configured maximum filesize of "%s"', $file->getFilename(), $this->maxFilesize));
     }
 }
开发者ID:sulu,项目名称:sulu,代码行数:26,代码来源:FileValidator.php

示例2: moveUploadedFile

 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath, $fileName)
 {
     $originalName = $file->getFilename();
     // use filemtime() to have a more determenistic way to determine the subpath, otherwise its hard to test.
     // $relativePath = date('Y-m', filemtime($file->getPath()));
     $targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
     $targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
     $ext = $file->getExtension();
     $i = 1;
     while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
         if ($ext) {
             $prev = $i == 1 ? "" : $i;
             $targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
         } else {
             $targetFilePath = $targetFilePath . $i++;
         }
     }
     $targetDir = $uploadBasePath . DIRECTORY_SEPARATOR . $relativePath;
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, umask(), true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     //$file->move($targetDir, basename($targetFilePath));
     //$file->move($targetDir, basename($fileName.'.'.$ext));
     $file->move($targetDir, basename($fileName));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
开发者ID:alangalipaud,项目名称:ProjetQCM,代码行数:29,代码来源:UploadFileMover.php

示例3: moveUploadedFile

 public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath)
 {
     $originalName = $file->getFilename() . '.' . $file->guessExtension();
     $targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
     $targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
     $ext = $file->getExtension();
     $i = 1;
     while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
         if ($ext) {
             $prev = $i == 1 ? "" : $i;
             $targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
         } else {
             $targetFilePath = $targetFilePath . $i++;
         }
     }
     $targetDir = 'uploads';
     if (!is_dir($targetDir)) {
         $ret = mkdir($targetDir, 777, true);
         if (!$ret) {
             throw new \RuntimeException("Could not create target directory to move temporary file into.");
         }
     }
     $file->move($targetDir, basename($targetFilePath));
     return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
 }
开发者ID:kevin-ta,项目名称:Form-wizard,代码行数:25,代码来源:UploadFileMover.php

示例4: getFileArray

 /**
  * 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;
 }
开发者ID:RSSfeed,项目名称:UploadBundle,代码行数:13,代码来源:HandleUpload.php

示例5: moveUpload

 /**
  * Move an uploaded file from the /tmp directory of the local filesystem
  * to the configured location
  *
  * @param Symfony\Component\HttpFoundation\File\UploadedFile $file 
  * @return string $url A URL to to the file, resolveable in HTML
  */
 public function moveUpload(UploadedFile $file)
 {
     // Nest the uploaded file into unique sub directory and a unqiue name
     $path = $this->makeNestedAndUniquePath($file->getClientOriginalName());
     // Move the uploaded file to the destination using Flysystem and return
     // the new path
     $this->manager->move('tmp://' . $file->getFilename(), 'disk://' . $path);
     // Return the URL of the upload.
     return $this->helpers->url($path);
 }
开发者ID:albabar,项目名称:upchuck,代码行数:17,代码来源:Storage.php

示例6: saveImg

 /**
  * 保存一个图片到指定目录
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile|array $img
  * @param string $folder
  * @param int $width
  * @param int $height
  * @return string
  *
  * @throws FileException if, for any reason, the dictionary could not be created
  */
 public static function saveImg($img, $folder, $width = 300, $height = 270)
 {
     $clientName = $img->getClientOriginalName();
     $tmpName = $img->getFilename();
     $realPath = $img->getRealPath();
     $extension = $img->getClientOriginalExtension();
     $mimeType = $img->getMimeType();
     $newName = md5(date('ymdhis') . $clientName) . "." . $extension;
     // 目录不存在,创建之
     if (!is_dir($folder)) {
         if (false === @mkdir($folder, 0777, true) && !is_dir($folder)) {
             throw new FileException(sprintf('Unable to create the "%s" directory', $folder));
         }
     } elseif (!is_writable($folder)) {
         throw new FileException(sprintf('Unable to write in the "%s" directory', $folder));
     }
     // resizing an uploaded file,这样会创建一张新的图片
     Image::make($img)->fit($width, $height)->save($folder . '/' . $newName);
     return $newName;
 }
开发者ID:supermason,项目名称:homestreward,代码行数:31,代码来源:ImageUtil.php

示例7: unzip

 /**
  * Helper function to decompress zip files.
  * @param UploadedFile $file
  * @param $targetDirectory
  * @throws Exception
  */
 private function unzip(UploadedFile $file, $targetDirectory)
 {
     $filter = new \Zend_Filter_Decompress(array('adapter' => $file->getClientOriginalExtension(), 'options' => array('target' => $targetDirectory)));
     $filter->filter($file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename());
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:11,代码来源:Theme.php

示例8: getFilename

 /**
  * Get the new filename of file.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param array                                               $config
  *
  * @return string
  */
 protected function getFilename(UploadedFile $file, array $config)
 {
     $ext = '.' . ($file->getClientOriginalExtension() ?: $file->guessClientExtension());
     return str_finish($this->formatPath($config['path_format']), '/') . md5($file->getFilename()) . $ext;
 }
开发者ID:overtrue,项目名称:laravel-ueditor,代码行数:13,代码来源:StorageManager.php

示例9: createFromUploadedFile

 /**
  * @param UploadedFile $uploadedFile
  * @param string       $directory
  *
  * @return File|bool
  */
 public function createFromUploadedFile(UploadedFile $uploadedFile, $directory)
 {
     $file = File::createFromExistingFile($uploadedFile->getFilename(), $uploadedFile->getClientOriginalName(), $this->createDirs($uploadedFile->getFilename() . $uploadedFile->getClientOriginalName(), $directory));
     $movedFile = $uploadedFile->move($this->rootPath . $file->getDirectories(), $uploadedFile->getFilename());
     return $movedFile ? $file : false;
 }
开发者ID:da-vinci-studio,项目名称:file-bundle,代码行数:12,代码来源:FileFactory.php

示例10: path

 /**
  * {@inheritdoc}
  */
 public function path()
 {
     return $this->source->getPath() . '/' . $this->source->getFilename();
 }
开发者ID:plank,项目名称:laravel-mediable,代码行数:7,代码来源:UploadedFileAdapter.php

示例11: put

 public function put(UploadedFile $file, $whereToPut)
 {
     $this->file->move($file->getRealPath(), $whereToPut . "/" . $file->getFilename());
 }
开发者ID:hasangilak,项目名称:BlogatorFileManager,代码行数:4,代码来源:UploadManager.php

示例12: createThumb

 /**
  * Crea la miniatura de imagenes
  * @param UploadedFile $file 
  * @param string $path 
  * @return string Nombre del nuevo archivo
  */
 public function createThumb($file, $path)
 {
     $ext = $file->getExtension();
     $search = $this->config["images"]["images_ext"];
     if (array_search($ext, $search) !== false) {
         $fullpath = $this->getFullPath() . $path;
         $fullpaththumb = $this->getFullPath() . '/_thumbs' . $path;
         $filename = $file->getFilename();
         $filename_new = $this->removeExtension($filename) . '-' . $this->config['images']['resize']['thumbWidth'] . 'x' . $this->config['images']['resize']['thumbHeight'] . '.' . $file->getExtension();
         $fullpaththumb_name = $this->getFullPath() . '/_thumbs' . $path . $filename_new;
         if ($this->config['debug']) {
             $this->_log(__METHOD__ . " - {$fullpaththumb}");
         }
         $filethumb = new Filesystem();
         if ($filethumb->exists($fullpaththumb_name) == false) {
             if ($this->config['debug']) {
                 $this->_log(__METHOD__ . " - " . $fullpaththumb_name);
             }
             if ($filethumb->exists($fullpaththumb) == false) {
                 $filethumb->mkdir($fullpaththumb);
             }
             Imagen::open($fullpath . $file->getFilename())->zoomCrop($this->config['images']['resize']['thumbWidth'], $this->config['images']['resize']['thumbHeight'])->save($fullpaththumb_name);
         }
         return $filename_new;
     } else {
         if ($this->config['debug']) {
             $this->_log(__METHOD__ . " - {$ext}");
         }
     }
 }
开发者ID:guillermomartinez,项目名称:filemanager-php,代码行数:36,代码来源:Filemanager.php

示例13: getExifReadData

 /**
  * @param UploadedFile $fileObject
  * @return array
  */
 private function getExifReadData(UploadedFile $fileObject)
 {
     Log::debug($fileObject->getPath());
     Log::debug($fileObject->getFilename());
     Log::debug($fileObject->getBasename());
     Log::debug($fileObject->getClientMimeType());
     Log::debug($fileObject->getExtension());
     Log::debug($fileObject->getType());
     $result = [];
     $mimeType = $fileObject->getClientMimeType();
     // upload_igm and thumbnail directory make
     $dirName = date('Ym');
     $uploadDir = public_path() . '/upload_img/' . $dirName;
     $thumbnailDir = public_path() . '/thumbnail/' . $dirName;
     $this->chkDir($uploadDir);
     $this->chkDir($thumbnailDir);
     //@todo オリジナル動画をリサイズする
     $extension = explode('/', $fileObject->getClientMimeType())[1];
     $newFileName = sha1($fileObject->getFilename() . time()) . '.' . $extension;
     $saveFileName = $uploadDir . '/' . $newFileName;
     $fileObject->move($uploadDir, $newFileName);
     $thumbnail = Image::make(file_get_contents($saveFileName));
     $thumbnail->resize(100, null, function ($constraint) {
         $constraint->aspectRatio();
     });
     $thumbnail->save($thumbnailDir . '/' . $newFileName, 100);
     $result['file_name'] = $dirName . '/' . $newFileName;
     if ($mimeType !== 'image/jpeg') {
         return $result;
     }
     $exif = exif_read_data($saveFileName);
     if ($exif === false) {
         return false;
     }
     $result['file_date_time'] = isset($exif['DateTimeOriginal']) ? $exif['DateTimeOriginal'] : null;
     $result['file_size'] = $exif['FileSize'];
     $result['mime_type'] = $exif['MimeType'];
     $result['width'] = $exif['COMPUTED']['Width'];
     $result['height'] = $exif['COMPUTED']['Height'];
     $result['make'] = isset($exif['Make']) ? $exif['Make'] : null;
     $result['model'] = isset($exif['Model']) ? $exif['Model'] : null;
     $result['orientation'] = isset($exif['Orientation']) ? $exif['Orientation'] : null;
     if (isset($exif["GPSLatitude"])) {
         //緯度を60進数から10進数に変換
         $lat = $this->convert_float($exif["GPSLatitude"][0]) + $this->convert_float($exif["GPSLatitude"][1]) / 60 + $this->convert_float($exif["GPSLatitude"][2]) / 3600;
         //南緯の場合はマイナスにする
         if ($exif["GPSLatitudeRef"] == "S") {
             $lat *= -1;
         }
         //経度を60進数から10進数に変換
         $lng = $this->convert_float($exif["GPSLongitude"][0]) + $this->convert_float($exif["GPSLongitude"][1]) / 60 + $this->convert_float($exif["GPSLongitude"][2]) / 3600;
         //西経の場合はマイナスにする
         if ($exif["GPSLongitudeRef"] == "W") {
             $lng *= -1;
         }
         $result['lat'] = $lat;
         $result['lng'] = $lng;
     }
     return $result;
 }
开发者ID:picolit,项目名称:bbs,代码行数:64,代码来源:ArticleService.php

示例14: getFileName

 /**
  * Get the name of the file
  *
  * @param UploadedFile|File|string $file
  * @return string
  */
 protected function getFileName($file)
 {
     if ($file instanceof UploadedFile) {
         return $file->getClientOriginalName();
     } elseif ($file instanceof File) {
         return $file->getFilename();
     } else {
         return basename($file);
     }
 }
开发者ID:davamigo,项目名称:translator-bundle,代码行数:16,代码来源:ExcelImporter.php

示例15: parseOriginalTags

 /**
  * Extracts a file's tags.
  *
  * @param UploadedFile $file
  * @param User $artist
  * @param string $audioCodec
  * @return array the "processed" and raw tags extracted from the file
  * @throws \Exception
  */
 protected function parseOriginalTags(UploadedFile $file, User $artist, string $audioCodec)
 {
     //==========================================================================================================
     // Extract the original tags.
     //==========================================================================================================
     $getId3 = new getID3();
     // all tags read by getID3, including the cover art
     $allTags = $getId3->analyze($file->getPathname());
     // tags specific to a file format (ID3 or Atom), pre-normalization but with cover art removed
     $rawTags = [];
     // normalized tags used by Pony.fm
     $parsedTags = [];
     if ($audioCodec === 'mp3') {
         list($parsedTags, $rawTags) = $this->getId3Tags($allTags);
     } elseif (Str::startsWith($audioCodec, 'aac')) {
         list($parsedTags, $rawTags) = $this->getAtomTags($allTags);
     } elseif ($audioCodec === 'vorbis') {
         list($parsedTags, $rawTags) = $this->getVorbisTags($allTags);
     } elseif ($audioCodec === 'flac') {
         list($parsedTags, $rawTags) = $this->getVorbisTags($allTags);
     } elseif (Str::startsWith($audioCodec, ['pcm', 'adpcm'])) {
         list($parsedTags, $rawTags) = $this->getAtomTags($allTags);
     }
     //==========================================================================================================
     // Fill in the title tag if it's missing
     //==========================================================================================================
     $parsedTags['title'] = $parsedTags['title'] ?? pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
     //==========================================================================================================
     // Determine the release date.
     //==========================================================================================================
     if ($parsedTags['release_date'] === null && $parsedTags['year'] !== null) {
         $parsedTags['release_date'] = Carbon::create($parsedTags['year'], 1, 1);
     }
     //==========================================================================================================
     // Does this track have vocals?
     //==========================================================================================================
     $parsedTags['is_vocal'] = $parsedTags['lyrics'] !== null;
     //==========================================================================================================
     // Determine the genre.
     //==========================================================================================================
     $genreName = $parsedTags['genre'];
     if ($genreName) {
         $parsedTags['genre_id'] = $this->getGenreId($genreName);
     } else {
         $parsedTags['genre_id'] = $this->getGenreId('Unknown');
     }
     //==========================================================================================================
     // Extract the cover art, if any exists.
     //==========================================================================================================
     $coverId = null;
     if (array_key_exists('comments', $allTags) && array_key_exists('picture', $allTags['comments'])) {
         $image = $allTags['comments']['picture'][0];
         if ($image['image_mime'] === 'image/png') {
             $extension = 'png';
         } elseif ($image['image_mime'] === 'image/jpeg') {
             $extension = 'jpg';
         } else {
             throw new BadRequestHttpException('Unknown cover format embedded in the track file!');
         }
         // write temporary image file
         $tmpPath = Config::get('ponyfm.files_directory') . '/tmp';
         $filename = $file->getFilename() . ".cover.{$extension}";
         $imageFilePath = "{$tmpPath}/{$filename}";
         File::put($imageFilePath, $image['data']);
         $imageFile = new UploadedFile($imageFilePath, $filename, $image['image_mime']);
         $cover = Image::upload($imageFile, $artist);
         $coverId = $cover->id;
     } else {
         // no cover art was found - carry on
     }
     $parsedTags['cover_id'] = $coverId;
     //==========================================================================================================
     // Is this part of an album?
     //==========================================================================================================
     $albumId = null;
     $albumName = $parsedTags['album'];
     if ($albumName !== null) {
         $albumId = $this->getAlbumId($artist->id, $albumName, $coverId);
     }
     $parsedTags['album_id'] = $albumId;
     return [$parsedTags, $rawTags];
 }
开发者ID:nsystem1,项目名称:Pony.fm,代码行数:91,代码来源:UploadTrackCommand.php


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