本文整理汇总了PHP中League\Flysystem\FilesystemInterface::getMimetype方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::getMimetype方法的具体用法?PHP FilesystemInterface::getMimetype怎么用?PHP FilesystemInterface::getMimetype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::getMimetype方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create the response.
*
* @param \League\Flysystem\FilesystemInterface $cache The cache file system.
* @param string $path The cached file path.
*
* @return \Cake\Network\Response The response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $cache->readStream($path);
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$response = new Response();
$response->type($contentType);
$response->header('Content-Length', $contentLength);
$response->body(function () use($stream) {
rewind($stream);
fpassthru($stream);
fclose($stream);
});
return $response;
}
示例2: find
/**
* {@inheritdoc}
*/
public function find($path)
{
if ($this->filesystem->has($path) === false) {
throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
}
$mimeType = $this->filesystem->getMimetype($path);
return new Binary($this->filesystem->read($path), $mimeType, $this->extensionGuesser->guess($mimeType));
}
示例3: setHeaders
/**
* Set the streamed response headers.
* @param StreamedResponse $response The response object.
* @return StreamedResponse
*/
public function setHeaders(StreamedResponse $response)
{
$response->headers->set('Content-Type', $this->cache->getMimetype($this->path));
$response->headers->set('Content-Length', $this->cache->getSize($this->path));
$response->setPublic();
$response->setMaxAge(31536000);
$response->setExpires(date_create()->modify('+1 years'));
$response->setLastModified(date_create()->setTimestamp($this->cache->getTimestamp($this->path)));
$response->isNotModified($this->request);
return $response;
}
示例4: _stat
/**
* Return stat for given path.
* Stat contains following fields:
* - (int) size file size in b. required
* - (int) ts file modification time in unix time. required
* - (string) mime mimetype. required for folders, others - optionally
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally
*
* If file does not exists - returns empty array or false.
*
* @param string $path file path
* @return array|false
**/
protected function _stat($path)
{
$stat = array('mime' => 'directory', 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'size' => 0);
// If root, just return from above
if ($this->root == $path) {
$stat['name'] = $this->root;
return $stat;
}
// If not exists, return empty
if (!$this->fs->has($path)) {
return array();
}
$meta = $this->fs->getMetadata($path);
// Get timestamp/size
$stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
$stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
// Check if file, if so, check mimetype
if ($meta['type'] == 'file') {
$stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
$imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
$stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
$stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
}
}
if (!isset($stat['url']) && $this->fs->getUrl()) {
$stat['url'] = 1;
}
return $stat;
}
示例5: _stat
/**
* Return stat for given path.
* Stat contains following fields:
* - (int) size file size in b. required
* - (int) ts file modification time in unix time. required
* - (string) mime mimetype. required for folders, others - optionally
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally
*
* If file does not exists - returns empty array or false.
*
* @param string $path file path
* @return array|false
**/
protected function _stat($path)
{
$stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory');
// If root, just return from above
if ($this->root == $path) {
$stat['name'] = $this->root;
return $stat;
}
// If not exists, return empty
if (!$this->fs->has($path)) {
// Check if the parent doesn't have this path
if ($this->_dirExists($path)) {
return $stat;
}
// Neither a file or directory exist, return empty
return array();
}
try {
$meta = $this->fs->getMetadata($path);
} catch (\Exception $e) {
return array();
}
if (false === $meta) {
return $stat;
}
// Set item filename.extension to `name` if exists
if (isset($meta['filename']) && isset($meta['extension'])) {
$stat['name'] = $meta['filename'];
if ($meta['extension'] !== '') {
$stat['name'] .= '.' . $meta['extension'];
}
}
// Get timestamp/size if available
if (isset($meta['timestamp'])) {
$stat['ts'] = $meta['timestamp'];
}
if (isset($meta['size'])) {
$stat['size'] = $meta['size'];
}
// Check if file, if so, check mimetype when available
if ($meta['type'] == 'file') {
if (isset($meta['mimetype'])) {
$stat['mime'] = $meta['mimetype'];
} else {
$stat['mime'] = $this->fs->getMimetype($path);
}
$imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
$stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
$stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
}
}
if (!isset($stat['url']) && $this->fs->getUrl()) {
$stat['url'] = 1;
}
return $stat;
}
示例6: getMimetype
/**
* @override
* @inheritDoc
*/
public function getMimetype($path)
{
try {
return $this->fs->getMimetype($path);
} catch (Error $ex) {
} catch (Exception $ex) {
}
throw new ReadException("File {$path} mimetype could not be determined.", $ex);
}
示例7: create
/**
* Create response.
* @param FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
* @return Response Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $this->streamCallback->__invoke($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$cacheControl = 'max-age=31536000, public';
$expires = date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT';
return $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
}
示例8: outputImage
/**
* Generate and output image.
* @param string $path Image path.
* @param array $params Image manipulation params.
* @throws InvalidArgumentException
*/
public function outputImage($path, array $params)
{
$path = $this->makeImage($path, $params);
header('Content-Type:' . $this->cache->getMimetype($path));
header('Content-Length:' . $this->cache->getSize($path));
header('Cache-Control:' . 'max-age=31536000, public');
header('Expires:' . date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT');
$stream = $this->cache->readStream($path);
rewind($stream);
fpassthru($stream);
fclose($stream);
}
示例9: create
/**
* Create response.
*
* @param \League\Flysystem\FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
*
* @return \Psr\Http\Message\ResponseInterface Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = new Stream($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
if ($contentType === false) {
throw new FilesystemException('Unable to determine the image content type.');
}
if ($contentLength === false) {
throw new FilesystemException('Unable to determine the image content length.');
}
return (new Response())->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength);
}
示例10: create
/**
* Create response.
* @param FilesystemInterface $cache Cache file system.
* @param string $path Cached file path.
* @return ResponseInterface Response object.
*/
public function create(FilesystemInterface $cache, $path)
{
$stream = $this->streamCallback->__invoke($cache->readStream($path));
$contentType = $cache->getMimetype($path);
$contentLength = (string) $cache->getSize($path);
$cacheControl = 'max-age=31536000, public';
$expires = date_create('+1 years')->format('D, d M Y H:i:s') . ' GMT';
if ($contentType === false) {
throw new FilesystemException('Unable to determine the image content type.');
}
if ($contentLength === false) {
throw new FilesystemException('Unable to determine the image content length.');
}
return $this->response->withBody($stream)->withHeader('Content-Type', $contentType)->withHeader('Content-Length', $contentLength)->withHeader('Cache-Control', $cacheControl)->withHeader('Expires', $expires);
}
示例11: uploadFile
protected function uploadFile(UploadedFileInterface $content, $mime, $filePath)
{
$uri = $content->getStream()->getMetadata('uri');
if (!$uri) {
throw new SaveResourceErrorException('Unknown error: can\'t get uploaded file uri');
}
$uploadedMime = $this->filesystem->getMimetype($uri);
if ($mime !== $uploadedMime) {
/**
* Try to remove unnecessary file because UploadFile object can be emulated
* @see \Staticus\Middlewares\ActionPostAbstract::download
*/
$this->filesystem->delete($uri);
throw new WrongRequestException('Bad request: incorrect mime-type of the uploaded file');
}
$content->moveTo($filePath);
}
示例12: createResponseFor
/**
* Generate an {@see SS_HTTPResponse} for the given file from the source filesystem
* @param FilesystemInterface $flysystem
* @param string $fileID
* @return SS_HTTPResponse
*/
protected function createResponseFor(FilesystemInterface $flysystem, $fileID)
{
// Build response body
// @todo: gzip / buffer response?
$body = $flysystem->read($fileID);
$mime = $flysystem->getMimetype($fileID);
$response = new SS_HTTPResponse($body, 200);
// Add headers
$response->addHeader('Content-Type', $mime);
$headers = Config::inst()->get(get_class($this), 'file_response_headers');
foreach ($headers as $header => $value) {
$response->addHeader($header, $value);
}
return $response;
}
示例13: getMimetype
/**
* Get the file's mimetype.
*
* @return string
*/
public function getMimetype()
{
return $this->filesystem->getMimetype($this->path);
}
示例14: getMimetype
/**
* Get a file's mime-type.
*
* @param string $path The path to the file.
*
* @throws FileNotFoundException
*
* @return string|false The file mime-type or false on failure.
*/
public function getMimetype($path)
{
return $this->fileSystem->getMimetype($path);
}
示例15: getMimeType
public function getMimeType($spiBinaryFileId)
{
return $this->filesystem->getMimetype($spiBinaryFileId);
}