我正在寻找将torrent一样的将单个文件拆分为多个文件的代码。
我将尝试作为Web应用程序进行尝试。所以我需要后端的代码
当用户输入200mb的文件时;输出必须将文件分成较小的部分,例如20kb / file
答案 0 :(得分:0)
你去...
// 20 KB
$partSize = 20 * 1024;
$fileSize = filesize($theFile);
$fileNameTemplate = __DIR__ . '/split_no_%04d.whatever';
$fileHandle = fopen($theFile, 'r');
$counter = 0;
while($fileSize > 0 && !feof($fileHandle)) {
$counter++;
// create a new filename
$newFile = sprintf($fileNameTemplate, $counter);
// open new file
$writeHandle = fopen($newFile, 'w');
// read portion of the big file
$content = fread($fileHandle, $partSize);
// write it to the new file
$written = fwrite($writeHandle, $content);
// close file pointer
fclose($writeHandle);
// adjust remaining bytes
$fileSize -= $written;
echo '- '. $written . ' bytes'. PHP_EOL;
}