stnvh / php-partialzip
此软件包最新版本(0.2.1)没有提供许可信息。
下载位于远程ZIP文件内的文件
0.2.1
2016-11-01 17:49 UTC
Requires
- php: >=5.3.2
README
PHP Partial Zip 允许您下载位于远程ZIP文件内的文件。
使用方法
composer require stnvh/php-partialzip 0.2.x
方法使用
__construct($url, $file = false)
类初始化方法
$p = new Partial('http://some.site.com/cats.zip');
index()
返回远程目录中所有文件的列表
/*...*/ $list = $p->index(); # = ('cat.png', 'cat2.png', 'cat3.png')
find($fileName = false)
返回用于获取远程文件的解析文件对象
/*...*/ # Search and return other file objects if($file = $p->find('cat2.png')) { # You can call methods here to fetch ZIP header information too # The full list of file header properties can be found in CDFile.php $size = $file->size(); # size in bytes $fullName = $file->name(); # full file name in zip, including path }
get($file)
返回或输出从远程ZIP文件获取的文件。
注意:在echo ->get()之前,您应确保没有输出内容,因为这会导致文件下载包含无效数据。提示:在脚本开始时使用ob_start(),然后在输出之前运行ob_clean()。
/*...*/ if($file = $p->find('cat3.png')) { $fileData = $p->get($file); }
示例
<?php require 'vendor/autoload.php'; use Stnvh\Partial\Zip as Partial; ob_start(); # will capture all output $p = new Partial('http://some.site.com/cats.zip'); # Get file object if($file = $p->find('cat.png')) { # removes everything from current output to ensure file downloads correctly ob_clean(); # Set appropriate headers and output to browser: header(sprintf('Content-Disposition: attachment; filename="%s"', $file->filename)); header(sprintf('Content-Length: %d', $file->size)); echo $p->get($file); }