Web Design Articles
Viewing entries posted in May 2013
Serving larger files via PHP readfile() function
header('Content-Transfer-Encoding: binary'); header('Content-Type: '.$mime_type); header('Content-Length: '.$size); if ( $mime_type != 'video/x-flv') header('Content-Disposition: attachment; filename="'.$filename.'"'); $chunksize = 1 * (1024 * 1024); // how many bytes per chunk if ($size > $chunksize) { $handle = fopen($file, 'rb'); $buffer = ''; while (!feof($handle)) { $buffer = fread($handle, $chunksize); echo $buffer; ob_flush(); flush(); } fclose($handle); } else { readfile($file); }
