【问题标题】:Handle file chunks from Dropzone in Laravel在 Laravel 中处理来自 Dropzone 的文件块
【发布时间】:2020-05-15 00:55:02
【问题描述】:

我尝试使用pionl/laravel-chunk-upload,但它不适用于 Laravel 7。我还尝试像以下那样组合块。

foreach ($chunks as $chunk) {
    // open the chunk file
    $file = fopen($chunk->getRealPath(), 'rb');
    // read the data & store it in a variable (each chunk is 20mb)
    $buff = fread($file, 2097152);
    fclose($file);
    // open the output file
    $total = fopen($out, 'ab');
    // write the data in it
    fwrite($total, $buff);
    fclose($total);
}

它将块合并为一个具有原始大小的文件,但它不起作用,并且丢失了视频或图像信息。

【问题讨论】:

标签: image video chunks laravel-7 dropzone


【解决方案1】:

我没有存储块文件的数据并将其写入文件,而是使用 PHP 函数file_get_contents($chunk_path) 来获取块数据。

$file = fopen($temp_file_path, 'w');

for ($i = 0; $i < $total_chunks; $i++) {
    $chunk_path = "{$temp_dir}/{$file_name}.part{$i}";
    
    if (!is_file($part_path)) {
        File::deleteDirectory($temp_dir);
        abort(404);
    }

    fwrite($file, file_get_contents($chunk_path));

}

fclose($file);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    • 2019-05-23
    • 2020-11-24
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    相关资源
    最近更新 更多