So for example, I have a file being uploaded through ftp and file size changes. I do know the file size beforehand. So how would I make php to send it to clients browsers even if file is not finished uploading and waiting for file size to match before it finish buffering. The code below won't update the handle and doesn't see changes made to file. I could pass fopen everytime but maybe there is a proper way? Thanks
$buffer = '';
$cnt =0;
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while ($cnt < $totalSize) {
$buffer = fread($handle, 2048);
echo $buffer;
ob_flush();
flush();
$bufferLen = strlen($buffer);
$cnt += $bufferLen;
if(!$bufferLen) sleep(1);
}
fclose($handle);