Download the PHP package yangwenqu/file_chunk without Composer

On this page you can find all versions of the php package yangwenqu/file_chunk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package file_chunk

整合大文件分片上传,下载功能(如果需要在window环境运行,需要修改getChunk方法里的获取硬盘空间方法)

* nginx配置client_max_body_size;
* php配置post_max_size、upload_max_filesize、memory_limit、max_input_time

分片上传

断点下载

上传示例代码


//1.客户端上传文件前进行获取分片大小和唯一文件名
try {
    $file  = new Upload();
    $file->init([
        'redis'               =>[
            'scheme' => 'tcp',
            'host'   => '127.0.0.1',
            'port'   => 6379,
        ],
        'clear_interval_time' => 60,                                // 清理临时文件间隔,默认五分钟
        'disk_min_size'       => 20    // 服务器空间最低剩余空间,超过此空间将不接收分片
    ]);
    $res = $file->getChunk(10 * 1024 * 1024 ,'a.b.c.exe');
    if(!$res){
        echo "服务器空间不足,请联系客服扩容";
    }
    echo $res;  // { ["chunk_size"]=> float(524288) ["file_name"]=> string(42) "27ad9ac14aa35137552ab038e038a6b8-a.b.c.exe" }

}catch (Exception $exception){

    var_dump($exception->getMessage());
    var_dump($exception->getTraceAsString());
}

//2.客户端上传每个分片前请求接口来获取当前文件是否超时,之前的分片是否被清理,如果被请求则拒绝处理。返回客户端错误码,让客户端不再续传剩余分片
$file  = new Upload();
$file->init([
    'redis'               =>
        'scheme' => 'tcp',
        'host'   => '127.0.0.1',
        'port'   => 6379,
    ],
    'clear_interval_time' => 60,                                // 清理临时文件间隔,默认五分钟
]);
$is_clear = $file->check('27ad9ac14aa35137552ab038e038a6b8-a.b.c.exe');
echo $is_clear;

//3.进行接收分片处理
$param = $_REQUEST;
$res   = $file->upload([
    'redis'               =>[
        'scheme' => 'tcp',
        'host'   => '127.0.0.1',
        'port'   => 6379,
    ],                                                          // predis的配置
    'tmp_name'            => $_FILES['file']['tmp_name'],       // 文件内容
    'now_package_num'     => $param['blob_num'],                // 当前文件包数量
    'total_package_num'   => $param['total_blob_num'],          // 文件包总量
    'file_name'           => $param['file_name'],               // 唯一文件名称
    'file_path'           => './upload',                        // 文件存放路径
    'clear_interval_time' => 60,                                // 清理临时文件间隔,默认五分钟
    'is_continuingly'     => true,                              // 是否断点续传,默认为true
    'tmp_file_chunk'      => '/tmp/file_chunk'                  // 临时分片存放目录
]);
if (is_string($res)){
    return "文件合并成功";
}else{
    return "当前分片上传成功,当前分片编号是:{$res}";
}

//4.定时器执行清理碎片
$file  = new Upload();
$file->init([
    'redis'               =>[
        'scheme' => 'tcp',
        'host'   => '127.0.0.1',
        'port'   => 6379,
    ],
    'clear_interval_time' => 60,                                // 清理临时文件间隔,默认五分钟
    'tmp_file_chunk'      => '/tmp/file_chunk'                  // 临时分片存放目录
]);
$file->claerChunk();

//5.获取某个文件缺少的分片(用于在上传周期中进行补传分片)
$file  = new Upload();
$file->init([
    'redis'               =>[
        'scheme' => 'tcp',
        'host'   => '127.0.0.1',
        'port'   => 6379,
    ],
]);
$file->getFailChunk('27ad9ac14aa35137552ab038e038a6b8-a.b.c.exe');

下载示例代码

注意:在下载http请求头中加入Range字段 Range: bytes=start-end [表示从start读取,一直读取到end位置,第一次请求这里可以1-2000,第二次根据响应中的文件总字节自行计算每次分片下载的字节范围]


$path     = './static/CentOS-7-x86_64-Everything-2009.iso';  //需要下载的文件目录+文件名
$filename = 'CentOS2009.iso';                                //下载保存的文件名
$file     = new Download();
$file->setSpeed(2)->download($path, $filename,true);         //限速2MB

响应示例


HTTP/1.1 206 Partial Content     //断点续传http响应码为206
content-length=106786028         //剩余字节
content-range=bytes 2000070-106786027/106786028   //正在下载的字节范围 / 文件总字节
content-type=application/octet-stream    //mime类型:octet-stream 

All versions of file_chunk with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
predis/predis Version v1.1.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yangwenqu/file_chunk contains the following files

Loading the files please wait ....