本文整理匯總了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;
}