note 88673 modified in function.popen by danbrown

From: Date: Tue, 03 Feb 2009 18:46:36 +0000
Subject: note 88673 modified in function.popen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-150156@lists.php.net to get a copy of this message
If you want to download files from a linux server with a filesize bigger than 2GB you can use the following: <?php function serveFile( $file , $as ){ header( 'Expires: Mon, 1 Apr 1974 05:00:00 GMT' ); header( 'Pragma: no-cache' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Content-Description: File Download' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Length: '.trim(stat -c%s "$file") ); header( 'Content-Disposition: attachment; filename="'. $as .'"' ); header( 'Content-Transfer-Encoding: binary' ); //@readfile( $file ); flush(); $fp = popen("tail -c ".trim(stat -c%s "$file")." ".$file.' 2>&1', "r"); while(!feof($fp)) { // send the current file part to the browser print fread($fp, 1024); // flush the content to the browser flush(); } fclose($fp); } ?> --was-- If you want to download files from a linux server with a filesize bigger than 2GB you can use the following: <? function serveFile( $file , $as ){ header( 'Expires: Mon, 1 Apr 1974 05:00:00 GMT' ); header( 'Pragma: no-cache' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Content-Description: File Download' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Length: '.trim(stat -c%s "$file") ); header( 'Content-Disposition: attachment; filename="'. $as .'"' ); header( 'Content-Transfer-Encoding: binary' ); //@readfile( $file ); flush(); $fp = popen("tail -c ".trim(stat -c%s "$file")." ".$file.' 2>&1', "r"); while(!feof($fp)) { // send the current file part to the browser print fread($fp, 1024); // flush the content to the browser flush(); } fclose($fp); } ?> http://php.net/manual/en/function.popen.php

« previous php.notes (#150156) next »