コード例 #1
2
ファイル: GenericDownloader.php プロジェクト: arbi/MyCode
 /**
  * @param $filePath
  * @param $toBeDownloadedFileName
  *
  * @return int
  */
 public function downloadAttachment($filePath, $toBeDownloadedFileName = '')
 {
     if (!is_readable($this->currentPath . $filePath)) {
         $this->setError(self::ERROR_ATTACHMENT_FILE_DOES_NOT_EXIST);
     }
     if (empty($toBeDownloadedFileName)) {
         $toBeDownloadedFileName = basename($filePath);
         if (empty($toBeDownloadedFileName)) {
             $this->setError(self::ERROR_ATTACHMENT_DOES_NOT_EXIST);
         }
     }
     if ($this->hasError()) {
         return $this->errors;
     }
     $this->setHeadersForAttachmentDownload($toBeDownloadedFileName);
     if ($this->fileSystem->getSize($filePath) > DirectoryStructure::FS_DOWNLOAD_STREAM_AFTER_SIZE) {
         header('Content-Length: ' . $this->fileSystem->getSize($filePath));
         $stream = $this->fileSystem->readStream($filePath);
         while (!feof($stream)) {
             print fgets($stream, 1024);
             flush();
         }
         fclose($stream);
         exit;
     } else {
         ob_start();
         ob_start("ob_gzhandler");
         echo $this->fileSystem->get($filePath)->read();
         ob_end_flush();
         $gzippedContent = ob_get_contents();
         // store gzipped content to get size
         header('Content-Length: ' . strlen($gzippedContent));
         ob_end_flush();
         exit;
     }
 }
コード例 #2
0
ファイル: flysystem.php プロジェクト: ninjasilicon/core
	/**
	 * {@inheritdoc}
	 */
	public function filesize($path) {
		if ($this->is_dir($path)) {
			return 0;
		} else {
			return $this->flysystem->getSize($this->buildPath($path));
		}
	}
コード例 #3
0
 /**
  * Deploy files to the remote filesystem.
  *
  * @return void
  */
 public function deployToRemote()
 {
     $local_path = $this->relativeDumpPath();
     $files = $this->localAdapter->listContents($local_path);
     foreach ($files as $file) {
         $contents = $this->localAdapter->readStream($local_path . $file['basename']);
         $file_size = $this->localAdapter->getSize($local_path . $file['basename']);
         $this->out($this->parseString('Uploading %s (%s)', [$file['basename'], $this->formatBytes($file_size)], 'light_green'));
         $this->remoteAdapter->writeStream($local_path . $file['basename'], $contents);
     }
 }
コード例 #4
0
 /**
  * @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;
 }
コード例 #5
0
ファイル: VideoController.php プロジェクト: nandeeshmp/app
 public function stream($video)
 {
     if (!Auth::user()->can('view-video')) {
         return view('errors.denied');
     }
     $filesystem = new Filesystem(new Adapter(base_path()));
     $location = '/files/video/' . $video;
     $stream = $filesystem->readStream($location);
     $headers = ["Content-Type" => $filesystem->getMimetype($location), "Content-Length" => $filesystem->getSize($location), "Content-disposition" => "attachment; filename=\"" . basename($location) . "\""];
     return Response::stream(function () use($stream) {
         fpassthru($stream);
     }, 200, $headers);
 }
コード例 #6
0
ファイル: Filesystem.php プロジェクト: weyii/yii2-filesystem
 /**
  * Get the file size of a given file.
  *
  * @param  string  $path
  * @return int
  */
 public function size($path)
 {
     return parent::getSize($path);
 }
コード例 #7
0
 /**
  * @inheritdoc
  */
 public function getSize($path)
 {
     return $this->fileSystem->getSize($this->getInnerPath($path));
 }
コード例 #8
0
ファイル: Assets.php プロジェクト: fisharebest/laravel-assets
 /**
  * Render markup to load the CSS or JS assets.
  *
  * @param string[]          $attributes    Optional attributes, such as ['async']
  * @param string[]          $assets        The files to be processed
  * @param string            $extension     ".css" or ".js"
  * @param string            $source_dir    The folder containing the source assets
  * @param FilterInterface[] $filters       How to process these assets
  * @param string            $format_link   Template for an HTML link to the asset
  * @param string            $format_inline Template for an inline asset
  *
  * @return string
  */
 private function processAssets(array $attributes, array $assets, $extension, $source_dir, $filters, $format_link, $format_inline)
 {
     $hashes = [];
     $path = $this->getDestination();
     foreach ($assets as $asset) {
         if ($this->isAbsoluteUrl($asset)) {
             $hash = $this->hash($asset);
         } else {
             $hash = $this->hash($asset . $this->public->getTimestamp($source_dir . '/' . $asset));
         }
         if (!$this->public->has($path . '/' . $hash . $extension)) {
             if ($this->isAbsoluteUrl($asset)) {
                 $data = $this->getLoader()->loadUrl($asset);
             } else {
                 $data = $this->public->read($source_dir . '/' . $asset);
             }
             foreach ($filters as $filter) {
                 $data = $filter->filter($data, $asset, $this);
             }
             $this->public->write($path . '/' . $hash . $extension, $data);
             $this->public->write($path . '/' . $hash . '.min' . $extension, $data);
         }
         $hashes[] = $hash;
     }
     // The file name of our pipelined asset.
     $hash = $this->hash(implode('', $hashes));
     $asset_file = $path . '/' . $hash . '.min' . $extension;
     $this->concatenateFiles($path, $hashes, $hash, $extension);
     $this->concatenateFiles($path, $hashes, $hash, '.min' . $extension);
     $this->createGzip($asset_file);
     foreach ($this->notifiers as $notifier) {
         $notifier->created($asset_file);
     }
     if ($this->getDestinationUrl() === '') {
         $url = url($path);
     } else {
         $url = $this->getDestinationUrl();
     }
     if ($this->isEnabled()) {
         $inline_threshold = $this->getInlineThreshold();
         if ($inline_threshold > 0 && $this->public->getSize($asset_file) <= $inline_threshold) {
             return sprintf($format_inline, $this->public->read($asset_file));
         } else {
             return $this->htmlLinks($url, [$hash], '.min' . $extension, $format_link, $attributes);
         }
     } else {
         return $this->htmlLinks($url, $hashes, $extension, $format_link, $attributes);
     }
 }
コード例 #9
0
 public function testGetSize()
 {
     $this->assertInternalType('integer', $this->filesystem->getSize('2.txt'));
 }
コード例 #10
0
ファイル: FileManager.php プロジェクト: romeoz/rock-file
 /**
  * Get a file's size
  *
  * ```php
  * getSize('cache/file.tmp')
  * getSize('~/file.tmp$/')
  * ```
  *
  * @param  string $path path to file or regexp pattern
  * @return  int|false     file size or FALSE when fails
  *                        to check size of existing file
  */
 public function getSize($path)
 {
     if (StringHelper::isRegexp($path) && !($path = $this->searchByPattern($path))) {
         return false;
     }
     try {
         return parent::getSize($path);
     } catch (\Exception $e) {
         $this->errors[] = $e->getMessage();
     }
     return false;
 }