本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getMimeType方法的具体用法?PHP UploadedFile::getMimeType怎么用?PHP UploadedFile::getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: orientate
/**
* Orientate the image.
*
* @param UploadedFile $file
* @param $orientation
* @return UploadedFile
*/
protected function orientate(UploadedFile $file, $orientation)
{
$image = imagecreatefromjpeg($file->getRealPath());
switch ($orientation) {
case 2:
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 3:
$image = imagerotate($image, 180, 0);
break;
case 4:
$image = imagerotate($image, 180, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 5:
$image = imagerotate($image, -90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 6:
$image = imagerotate($image, -90, 0);
break;
case 7:
$image = imagerotate($image, 90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 8:
$image = imagerotate($image, 90, 0);
break;
}
imagejpeg($image, $file->getRealPath(), 90);
return new UploadedFile($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType(), $file->getSize());
}
示例2: upload
public static function upload(UploadedFile $file, $bucketName)
{
if (!$file->isValid()) {
throw new \Exception(trans('validation.invalid_file'));
}
$bucket = Bucket::find($bucketName);
if (!empty($bucket->mimeTypes()) && !in_array($file->getMimeType(), $bucket->mimeTypes())) {
throw new \Exception(trans('validation.invalid_file_type'));
}
if (!empty($bucket->maxSize()) && !in_array($file->getClientSize(), $bucket->maxSize())) {
throw new \Exception(trans('validation.invalid_file_size'));
}
$disk = Storage::disk($bucket->disk());
$media = Media::create(['mime' => $file->getMimeType(), 'bucket' => $bucketName, 'ext' => $file->guessExtension()]);
$disk->put($bucket->path() . '/original/' . $media->fileName, File::get($file));
if (is_array($bucket->resize())) {
foreach ($bucket->resize() as $name => $size) {
$temp = tempnam(storage_path('tmp'), 'tmp');
Image::make(File::get($file))->fit($size[0], $size[1])->save($temp);
$disk->put($bucket->path() . '/' . $name . '/' . $media->fileName, File::get($temp));
unlink($temp);
}
}
return $media;
}
示例3: mockStore
public function mockStore(Picture $pic, UploadedFile $dummy)
{
if ($dummy->getMimeType() != 'image/png') {
throw new \Exception('fail');
}
$pic->setStorageKey('123.jpg');
$pic->setMimeType($dummy->getMimeType());
}
示例4: upload
public function upload(UploadedFile $file)
{
if (!in_array($file->getMimeType(), $this->allowedMimeTypes)) {
throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getMimeType()));
}
$filename = sprintf('%s/%s/%s/%s.%s', date('Y'), date('m'), date('d'), uniqid(), $file->getClientOriginalExtension());
$adapter = $this->filesystem->getAdapter();
$adapter->setMetadata($filename, array('contentType' => $file->getMimeType()));
$adapter->write($filename, file_get_contents($file->getPathname()));
return $adapter->getUrl($filename);
}
示例5: processFile
/**
* Process image file, make it progressive
* @param UploadedFile $file
*/
public function processFile(UploadedFile $file)
{
$this->file = $file;
foreach (self::$IMAGE_TYPES as $type) {
if (in_array($this->file->getMimeType(), $type['mime_types'])) {
$filePath = $this->file->getRealPath();
$typeObject = new $type['class']($filePath);
$typeObject->process();
break;
}
}
}
示例6: upload
/**
* Upload (move) file to branch logos directory
* @param UploadedFile $logo
* @param null|string $targetFilename
* @return \Symfony\Component\HttpFoundation\File\File
* @throws LogoHandlerLogicException
*/
public function upload(UploadedFile $logo, $targetFilename = null)
{
if (!in_array($logo->getMimeType(), $this->permittedMimeTypes)) {
throw new LogoHandlerLogicException(sprintf('"%s" file type is not permitted. Use images for logo and try again.', $logo->getMimeType()));
}
if (is_null($targetFilename)) {
$targetFilename = sha1(uniqid(mt_rand(), true)) . '.' . $logo->guessExtension();
}
if (false === $this->branchLogoDir->isDir() || false === $this->branchLogoDir->isWritable()) {
throw new \RuntimeException(sprintf("Branch logo directory (%s) is not writable, doesn't exist or no space left on the disk.", $this->branchLogoDir->getRealPath()));
}
return $logo->move($this->branchLogoDir->getRealPath(), $targetFilename);
}
示例7: canUpload
/**
* {@inheritdoc}
*/
public function canUpload(UploadedFile $file)
{
$mimeType = $file->getMimeType();
if (in_array($mimeType, $this->getSupportedMimeTypes())) {
return 5;
}
if ($file->getMimeType() == 'application/ogg') {
// This could be a video or audio file.
$meta = GenericMetadataReader::readMetadata($file->getPathname());
if (isset($meta['audio']['dataformat'])) {
return 5;
}
}
return 0;
}
示例8: 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));
}
}
示例9: canUpload
/**
* {@inheritdoc}
*/
public function canUpload(UploadedFile $file)
{
if ($file->getMimeType() == 'text/plain' && $file->getClientOriginalExtension() == 'md') {
return 5;
}
return 0;
}
示例10: doUpload
/**
* {@inheritDoc}
*/
protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name)
{
$fs = $this->getFilesystem($mapping);
$path = !empty($dir) ? $dir . '/' . $name : $name;
$stream = fopen($file->getRealPath(), 'r+');
$fs->writeStream($path, $stream, array('mimetype' => $file->getMimeType()));
}
示例11: canUpload
/**
* {@inheritdoc}
*/
public function canUpload(UploadedFile $file)
{
$mimeType = $file->getMimeType();
if (in_array($mimeType, $this->getSupportedMimeTypes())) {
return 4;
}
return 0;
}
示例12: createVersionFromFile
/**
* @param AssetInterface $asset
* @param UploadedFile $file
*
* @return AssetVersion
*/
public function createVersionFromFile(AssetInterface $asset, UploadedFile $file)
{
list($width, $height) = getimagesize($file->getRealPath());
$extension = File::extension($file->getClientOriginalName(), $file->getMimetype());
$version = $this->version->create(['asset_id' => $asset->getId(), 'extension' => $extension, 'filesize' => $file->getClientSize(), 'filename' => $file->getClientOriginalName(), 'width' => $width, 'height' => $height, 'edited_at' => time(), 'edited_by' => Auth::getPerson()->getId(), 'mimetype' => $file->getMimeType(), 'metadata' => File::exif($file->getRealPath())]);
$file->move($asset->directory(), $version->id);
return $version;
}
示例13: testFileUploadsWithNoMimeType
public function testFileUploadsWithNoMimeType()
{
$file = new UploadedFile(__DIR__ . '/Fixtures/test.gif', 'original.gif', null, filesize(__DIR__ . '/Fixtures/test.gif'), UPLOAD_ERR_OK);
$this->assertEquals('application/octet-stream', $file->getClientMimeType());
if (extension_loaded('fileinfo')) {
$this->assertEquals('image/gif', $file->getMimeType());
}
}
示例14: doUpload
/**
* {@inheritDoc}
*/
protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name)
{
$filesystem = $this->getFilesystem($mapping);
$path = !empty($dir) ? $dir . '/' . $name : $name;
if ($filesystem->getAdapter() instanceof MetadataSupporter) {
$filesystem->getAdapter()->setMetadata($path, array('contentType' => $file->getMimeType()));
}
$filesystem->write($path, file_get_contents($file->getPathname()), true);
}
示例15: validate
/**
* Checks if the passed value is valid.
*
* @param UploadedFile $file The value that should be validated
* @param Constraint $constraint The constraint for the validation
*/
public function validate($file, Constraint $constraint)
{
if (!in_array($file->getMimeType(), $this->mimeTypes)) {
$this->context->buildViolation($constraint->messageMimeTypes)->atPath('file')->addViolation();
}
if ($file->getSize() > $file->getMaxFilesize()) {
$this->context->buildViolation($constraint->messageMaxSize, array('%max_size%' => $file->getMaxFilesize()))->atPath('file')->addViolation();
}
}