本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\File::guessExtension方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::guessExtension方法的具體用法?PHP File::guessExtension怎麽用?PHP File::guessExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\File\File
的用法示例。
在下文中一共展示了File::guessExtension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: preUpload
public function preUpload()
{
if (null !== $this->photo_file) {
// do whatever you want to generate a unique name
$this->nom = $this->getUser()->getUsername() . '.' . $this->photo_file->guessExtension();
}
}
示例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();
}
}
示例3: testGuessExtensionWithReset
/**
* @requires extension fileinfo
*/
public function testGuessExtensionWithReset()
{
$file = new File(__DIR__ . '/Fixtures/other-file.example');
$guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
MimeTypeGuesser::getInstance()->register($guesser);
$this->assertEquals('gif', $file->guessExtension());
MimeTypeGuesser::reset();
$this->assertNull($file->guessExtension());
}
示例4: 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');
}
}
示例5: testGuessExtensionIsBasedOnMimeType
public function testGuessExtensionIsBasedOnMimeType()
{
$file = new File(__DIR__ . '/Fixtures/test');
$guesser = $this->createMockGuesser($file->getPathname(), 'image/gif');
MimeTypeGuesser::getInstance()->register($guesser);
$this->assertEquals('gif', $file->guessExtension());
}
示例6: generateRelativePath
/**
* @param Contribution $contribution
* @param File $file
*
* @return string
*/
public function generateRelativePath(Contribution $contribution, File $file)
{
$path = $contribution->getAuthProvider() . DIRECTORY_SEPARATOR;
$path .= $contribution->getIdentifier();
$path .= '.' . ($file->guessExtension() ?: $file->getExtension());
return $path;
}
示例7: regenerateSpeakerPhotoPath
private function regenerateSpeakerPhotoPath($speaker)
{
// If speaker photo does not exist, null it out and return.
if (!$this->fileExists($speaker['photo_path'])) {
echo "[info] {$speaker['name']}'s photo was not found in file system. Removing record of it from profile." . PHP_EOL;
$this->execute("UPDATE users SET photo_path = '' WHERE id = {$speaker['id']}");
return;
}
// Need to guess extension. Cannot trust current file extensions.
$file = new File(__DIR__ . '/../web/uploads/' . $speaker['photo_path']);
$extension = $file->guessExtension();
// Otherwise, generate a new filename.
$generator = new PseudoRandomStringGenerator(new Factory());
$newFileName = $generator->generate(40) . '.' . $extension;
$oldFilePath = __DIR__ . '/../web/uploads/' . $speaker['photo_path'];
$newFilePath = __DIR__ . '/../web/uploads/' . $newFileName;
// If photo name is changed in file system, update record in database.
if (rename($oldFilePath, $newFilePath)) {
try {
$this->execute("UPDATE users SET photo_path = '{$newFileName}' WHERE id = '{$speaker['id']}'");
echo "[info] Regenerated photo path for {$speaker['name']}." . PHP_EOL;
} catch (\Exception $e) {
// If update fails for any reason, revert filename in file system.
rename($newFilePath, $oldFilePath);
}
}
}
示例8: upload
/**
* Handles image upload and resize
*
* @param string $context
* @param File $uploadedFile
* @param string $fileName
* @param bool $useHashAsFilename
*
* @return string
*/
public function upload($context, File $uploadedFile, $fileName = null, $useHashAsFilename = null)
{
if (null === $useHashAsFilename) {
$useHashAsFilename = $this->config['use_hash_as_image_name'];
}
$contextPath = $this->config['base_path'] . '/' . $context;
if (true === $useHashAsFilename) {
$fileName = $this->generateHash();
}
$fileName .= '.' . $uploadedFile->guessExtension();
if ($this->filesystem->exists($contextPath . '/' . $fileName) && true === $useHashAsFilename) {
$this->upload($contextPath, $uploadedFile, $fileName, $useHashAsFilename);
} elseif ($this->filesystem->exists($contextPath . '/' . $fileName) && false === $useHashAsFilename) {
throw new IcrLogicException("File {$fileName} exists! Please choose another name!");
}
// Upload original file
$this->filesystem->dumpFile($contextPath . '/' . $fileName, file_get_contents($uploadedFile->getRealPath()));
foreach ($this->config['contexts'][$context] as $sizeName => $values) {
// Process and manipulate
$manipulator = $this->manipulatorFactory->create($values['operation']);
$abstractImage = $this->openImageHandler->openImage($uploadedFile->getPathname());
$image = $manipulator->manipulate($abstractImage, $values['width'], $values['height']);
$path = $contextPath . '/' . $sizeName . '/';
$this->filesystem->dumpFile($path . '/' . $fileName, $image);
}
return $fileName;
}
示例9: getExtension
/**
* Use Symfony components to guess the file extension.
*
* @return string
* File extension
*/
public function getExtension()
{
if (!is_null($this->extension)) {
return $this->extension;
}
return $this->extension = $this->info->getExtension() ?: $this->info->guessExtension();
}
示例10: setFile
/**
* @param File $file
*
* @return $this
*/
public function setFile(File $file)
{
$this->file = $file;
if ($file->getPathname()) {
$this->filename = sha1(uniqid(mt_rand(), true)) . '.' . $file->guessExtension();
}
return $this;
}
示例11: preUpload
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if (null !== $this->file) {
$filename = sha1(uniqid(mt_rand(), true));
$this->path = $filename . '.' . $this->file->guessExtension();
$this->name = $this->getFile()->getClientOriginalName();
}
}
示例12: thumb
public function thumb(Request $request, $id)
{
$photo = Photo::findOrFail($id);
$file = new File($photo->path);
$photo->makeThumbnail();
$headers = array('Content-Type: ' . $file->getMimeType());
return response()->download($photo->path . '.' . $file->guessExtension(), $photo->name, $headers);
}
示例13: updateImage
/**
* @param \Exolnet\Image\Image $image
* @param \Symfony\Component\HttpFoundation\File\File $file
*/
public function updateImage(Image $image, File $file)
{
$this->destroy($image);
$fileName = $image->getId() . '-' . Str::slug($file->getBasename()) . '.' . $file->guessExtension();
$image->setFilename($fileName);
$image->save();
$this->store($image, $file);
}
示例14: moveFile
/**
* @param File $image
* @param string $prefix
* @param String $path
* @return string
*/
public function moveFile(File $image, $path, $prefix = '')
{
$extension = $image->guessExtension();
$code = strtoupper($this->request->get('code'));
$fileName = $code . '-' . $prefix . '.' . $extension;
$image->move(public_path() . $path, $fileName);
return $path . $fileName;
}
示例15: image64
/**
* Transform image to base 64
* @param string $path relative path to image from bundle directory
* @return string base64 encoded image
*/
public function image64($path)
{
$file = new File($path, false);
if (!$file->isFile() || 0 !== strpos($file->getMimeType(), 'image/')) {
return;
}
$binary = file_get_contents($path);
return sprintf('data:image/%s;base64,%s', $file->guessExtension(), base64_encode($binary));
}