在 Laravel 中处理来自 Dropzone 的文件块
Handle file chunks from Dropzone in Laravel
我尝试使用 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);
}
它将块合并为原始大小的 1 个文件,但它不起作用,并且会丢失视频或图像信息。
我没有存储chunk文件的数据并写入文件,而是使用PHP函数file_get_contents($chunk_path)
获取chunk数据
$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);
我尝试使用 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);
}
它将块合并为原始大小的 1 个文件,但它不起作用,并且会丢失视频或图像信息。
我没有存储chunk文件的数据并写入文件,而是使用PHP函数file_get_contents($chunk_path)
获取chunk数据
$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);