本文整理汇总了PHP中SplFileInfo::getClientOriginalName方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getClientOriginalName方法的具体用法?PHP SplFileInfo::getClientOriginalName怎么用?PHP SplFileInfo::getClientOriginalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getClientOriginalName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: name
/**
* @param \SplFileInfo $file
*
* @return string
*/
public function name(\SplFileInfo $file)
{
if ($file instanceof UploadedFile) {
return $this->escape($file->getClientOriginalName());
}
return parent::name($file);
}
示例2: getFileExtension
/**
* @param \SplFileInfo $fileInfo
* @return mixed|string
*/
private function getFileExtension(\SplFileInfo $fileInfo)
{
if ($fileInfo instanceof UploadedFile) {
return pathinfo($fileInfo->getClientOriginalName(), PATHINFO_EXTENSION);
}
return $fileInfo->getExtension();
}
示例3: generate
/**
* Generate all the path data of a file. If the original file name exceeds 100 characters, it is truncated.
* The file name is sanitized, and a unique ID is prepended.
*
* For example, a file called "this i#s the é file.txt'" will produce the following output:
* [
* 'uuid' => '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12',
* 'file_name' => '2fd4e1c67a2d28fced849ee1bb76e7391b93eb12_this_i_s_the___file.txt'
* 'path' => '2/f/d/4/',
* 'path_name' => '2/f/d/4/2fd4e1c67a2d28fced849ee1bb76e7391b93eb12_this_i_s_the___file.txt',
* ]
*
* @param \SplFileInfo $file
*
* @return array
*/
public function generate(\SplFileInfo $file)
{
$originalFileName = $file instanceof UploadedFile ? $file->getClientOriginalName() : $file->getFilename();
$uuid = $this->generateUuid($originalFileName);
$sanitized = preg_replace('#[^A-Za-z0-9\\.]#', '_', $originalFileName);
if (strlen($sanitized) > 100) {
$sanitized = sprintf('%s.%s', substr($sanitized, 0, 95), $file->getExtension());
}
$fileName = $uuid . '_' . $sanitized;
$path = sprintf('%s/%s/%s/%s/', $uuid[0], $uuid[1], $uuid[2], $uuid[3]);
$pathName = $path . $fileName;
return ['uuid' => $uuid, 'file_name' => $fileName, 'path' => $path, 'path_name' => $pathName];
}
示例4: create
/**
* {@inheritdoc}
*/
public function create(\SplFileInfo $rawFile, array $pathInfo, $destFsAlias)
{
if ($rawFile instanceof UploadedFile) {
$size = $rawFile->getClientSize();
$mimeType = $rawFile->getMimeType();
$originalFilename = $rawFile->getClientOriginalName();
$extension = $rawFile->getClientOriginalExtension();
} else {
$size = filesize($rawFile->getPathname());
$mimeType = MimeTypeGuesser::getInstance()->guess($rawFile->getPathname());
$originalFilename = $rawFile->getFilename();
$extension = $rawFile->getExtension();
}
$file = new $this->fileClass();
$file->setKey($pathInfo['path'] . $pathInfo['file_name']);
$file->setGuid($pathInfo['guid']);
$file->setMimeType($mimeType);
$file->setOriginalFilename($originalFilename);
$file->setSize($size);
$file->setExtension($extension);
$file->setStorage($destFsAlias);
return $file;
}