本文整理汇总了PHP中League\Flysystem\Filesystem::getMimetype方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::getMimetype方法的具体用法?PHP Filesystem::getMimetype怎么用?PHP Filesystem::getMimetype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::getMimetype方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @return bool
*/
public function execute()
{
if ($this->filesystem->getMimetype($this->filePath) == 'application/x-gzip') {
if ($this->filesystem->getMimetype(str_replace('.tar.gz', '', $this->filePath)) == 'directory') {
$this->filesystem->deleteDir(str_replace('.tar.gz', '', $this->filePath));
}
}
if ($this->filesystem->getMimetype($this->filePath) == 'directory') {
return $this->filesystem->deleteDir($this->filePath);
} else {
return $this->filesystem->delete($this->filePath);
}
}
示例2: assets
/**
* Return admin assets
* @param Response $response
* @param $asset
* @return Response|static
* @throws FileNotFoundException
*/
public function assets(Response $response, $asset)
{
$filesystem = new Filesystem(new Adapter(FS2ADMIN));
$expires = 8640000;
try {
// generate cache data
$timestamp_string = gmdate('D, d M Y H:i:s ', $filesystem->getTimestamp($asset)) . 'GMT';
$etag = md5($filesystem->read($asset));
$mime_type = $filesystem->getMimetype($asset);
if (0 !== strpos($mime_type, 'image')) {
$mime_type = 'text/css';
}
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
if (($if_none_match && $if_none_match == "\"{$etag}\"" || !$if_none_match) && ($if_modified_since && $if_modified_since == $timestamp_string)) {
return $response->withStatus('304');
} else {
$response = $response->withHeader('Last-Modified', $timestamp_string)->withHeader('ETag', "\"{$etag}\"");
}
// send out content type, expire time and the file
$response->getBody()->write($filesystem->read($asset));
return $response->withHeader('Expires', gmdate('D, d M Y H:i:s ', time() + $expires) . 'GMT')->withHeader('Content-Type', $mime_type)->withHeader('Pragma', 'cache')->withHeader('Cache-Control', 'cache');
} catch (FileNotFoundException $e) {
throw $e;
}
}
示例3: getMimetype
/**
* @inheritdoc
*/
public function getMimetype($path)
{
try {
return $this->fileSystem->getMimetype($this->getInnerPath($path));
} catch (FileNotFoundException $e) {
throw $this->exceptionWrapper($e, $path);
}
}
示例4: checkFileType
/**
* checkFileType
* @param array $file
* @param \League\Flysystem\Filesystem $fileReader
* @param $type
* @return bool
* @throws \eig\Configurator\Exceptions\ConfiguratorException
*/
protected function checkFileType(array $file, Filesystem $fileReader, $type)
{
$options = new Options();
if ($fileReader->getMimetype($file['source']) == $options->configurationFileTypes[$type]) {
return true;
} else {
throw new ConfiguratorException("Error {$file['source']} is not a PHP file", $code = 1);
}
}
示例5: getResources
function getResources($uploads_dir, $id, $maxWidth, $connection = 'default')
{
$attachments = Attachment::on($connection)->where('id', $id)->get();
if (count($attachments) == 1) {
$attachment = $attachments[0];
switch ($attachment->source) {
case Source::EMAIL:
$adapter = new Local($uploads_dir . '/email/');
break;
case Source::TWITTER:
$adapter = new Local($uploads_dir . '/twitter/');
break;
case Source::TELEGRAM:
$adapter = new Local($uploads_dir . '/telegram/');
break;
default:
break;
}
$filesystem = new Filesystem($adapter);
$filesystem->addPlugin(new ListWith());
if ($filesystem->has($attachment->filePath)) {
$data = $filesystem->read($attachment->filePath);
$fp['data'] = $data;
$fp['mime'] = $filesystem->getMimetype($attachment->filePath);
if ($maxWidth > 0) {
$imagine = new \Imagine\Gd\Imagine();
$image = $imagine->load($data);
$size = $image->getSize();
if ($size->getWidth() > $maxWidth) {
// AWIDTH : AHEIGHT = NWIDTH : NHEIGHT
// HHEIGHT = AHEIGHT * NWIDTH / AWIDTH
$height = $size->getHeight() * $maxWidth / $size->getWidth();
$width = $maxWidth;
$fp['data'] = $image->resize(new Box($width, $height), ImageInterface::FILTER_UNDEFINED)->show('png');
//FILTER_QUADRATIC
}
}
return $fp;
}
}
return false;
}
示例6: _stat
/**
* @inheritdoc
*/
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)) {
// return array();
// }
//
// $meta = $this->fs->getMetadata($path);
try {
$meta = $this->fs->getMetadata($path);
} catch (FileNotFoundException $e) {
$path = $path . '/';
try {
$meta = $this->fs->getMetadata($path);
} catch (FileNotFoundException $e) {
return array();
}
}
// 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;
}
示例7: image
/**
* Render image from filesystem
* @param $image
* @return mixed
*/
public function image($image)
{
$filesystem = new Filesystem(new Adapter(base_path()));
$location = '/files/video/' . $image;
$mime_type = $filesystem->getMimetype($location);
$file = $filesystem->read($location);
return response($file, 200)->header('Content-Type', $mime_type);
}
示例8: mimeType
/**
* Get the mime-type of a given file.
*
* @param string $path
* @return string|false
*/
public function mimeType($path)
{
return parent::getMimetype($path);
}
示例9: mimetype
/**
* @return string
*/
public function mimetype()
{
return $this->filesystem->getMimetype($this->path);
}
示例10: testGetMimetype
public function testGetMimetype()
{
$this->assertInternalType('string', $this->filesystem->getMimetype('2.txt'));
}
示例11: getMimetype
/**
* Get a file's mimetype
*
* ```php
* getMimetype('cache/file.tmp')
* getMimetype('~/file.tmp$/')
* ```
*
* @param string $path path to file or regexp pattern
* @return string|false file mimetype or FALSE when fails
* to fetch mimetype from existing file
*/
public function getMimetype($path)
{
if (StringHelper::isRegexp($path) && !($path = $this->searchByPattern($path))) {
return false;
}
try {
return parent::getMimetype($path);
} catch (\Exception $e) {
$this->errors[] = $e->getMessage();
}
return false;
}