/** * @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); } }
/** * 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; } }
/** * @inheritdoc */ public function getMimetype($path) { try { return $this->fileSystem->getMimetype($this->getInnerPath($path)); } catch (FileNotFoundException $e) { throw $this->exceptionWrapper($e, $path); } }
/** * 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); } }
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; }
/** * @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; }
/** * 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); }
/** * Get the mime-type of a given file. * * @param string $path * @return string|false */ public function mimeType($path) { return parent::getMimetype($path); }
/** * @return string */ public function mimetype() { return $this->filesystem->getMimetype($this->path); }
public function testGetMimetype() { $this->assertInternalType('string', $this->filesystem->getMimetype('2.txt')); }
/** * 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; }