本文整理汇总了PHP中SplFileInfo::getClientOriginalExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileInfo::getClientOriginalExtension方法的具体用法?PHP SplFileInfo::getClientOriginalExtension怎么用?PHP SplFileInfo::getClientOriginalExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileInfo
的用法示例。
在下文中一共展示了SplFileInfo::getClientOriginalExtension方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: attachFile
public function attachFile(\SplFileInfo $file)
{
$content = $file->openFile('r')->fread($file->getSize());
$extension = $file instanceof UploadedFile ? $file->getClientOriginalExtension() : $file->getExtension();
$this->attachContent($content, $extension);
}
示例3: saveToStorageAndGetFileEntity
protected function saveToStorageAndGetFileEntity(\SplFileInfo $uploadedFile)
{
$hash = md5_file($uploadedFile->getRealPath());
$folder1 = mb_substr($hash, 0, 2);
$folder2 = mb_substr($hash, 2, 2);
$folder3 = mb_substr($hash, 4, 2);
$this->destinationFolder = "{$folder1}/{$folder2}/{$folder3}";
$fileName = mb_substr($hash, 6) . ".{$uploadedFile->getClientOriginalExtension()}";
$file = $this->convertSavedFileToEntity($uploadedFile, $fileName);
$dir = "{$this->saveDirectory}/{$this->destinationFolder}";
if (!file_exists("{$dir}/{$fileName}")) {
mkdir($dir, 0777, true);
$uploadedFile->move($dir, $fileName);
}
return $file;
}