Download aus externem Ordner

Ich hab einfach mal gegoogled nach "php big files with readfile" und bin dabei auf die Funktion fpassthru() gestoßen. Die Comments dort waren sehr aufschlussreich und ich habe mich jetzt für diese Funktion entschieden...
PHP:
<?php
error_reporting(E_ALL);

/*/
Download a file using fpassthru()
/*/
$fileDir = "/path/tiarna/movie"; // supply a path name.
$fileName = "psa.tar.gz"; // supply a file name.
$fileString=$fileDir.'/'.$fileName; // combine the path and file
// translate file name properly for Internet Explorer.
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){
  $fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
}
// make sure the file exists before sending headers
if(!$fdl=@fopen($fileString,'r')){
   die("Cannot Open File!");
} else {
  header("Cache-Control: ");// leave blank to avoid IE errors
  header("Pragma: ");// leave blank to avoid IE errors
  header("Content-type: application/octet-stream");
  header("Content-Disposition: attachment; filename=\"".$fileName."\"");
  header("Content-length:".(string)(filesize($fileString)));
   sleep(1);
   fpassthru($fdl);
}


?>

Jemand noch etwas zu meckern? :)
 
Ja, es funktioniert wunderbar... Zumindest mit der Testfile von 197MB... Voraussetzung ist dass man nicht mit dem Buffering arbeitet... Also ob_flush etc. Sobald man solche Funktionen verwendet, bricht er alles wieder ab. So sieht mein Script jetzt aus:

PHP:
<?php
error_reporting(E_ALL);
function _get_browser()
{
  $browser = array ( //reversed array
   "OPERA",
   "MSIE",            // parent
   "NETSCAPE",
   "FIREFOX",
   "SAFARI",
   "KONQUEROR",
   "MOZILLA"        // parent
  );
 
  $parent = "OTHER";
  
  foreach ($browser as $parent) 
  {
   if ( ($s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) !== FALSE )
   {           
     $f = $s + strlen($parent);
     $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 8);
     $version = preg_replace('/[^0-9,.]/','',$version);
     
     $info = $parent." ".$version;
     break; // first match wins
   }
  }
 
  return $info;
}  

$ip = $_SERVER['REMOTE_ADDR'];
$time = time();

$file = "./access.db";
$info = _get_browser();

$movie = "psa.tar.gz";

$content = file($file);
$k = count($content);

for($i = 0; $i < $k; $i++) {
	$cont = explode(";", $content[$i]);
	if($cont[0] == $ip) {
		echo "<strong>Sie haben den Film bereits geladen!</strong>"; exit;
	} elseif($k == 600) {
		echo '<strong>Tut mir leid, aber es wurden bereits die maximal m&ouml;glichen Downloads geladen<br/>'.$k.'</strong>';
	}
}


$j = $k++;

$content[$j] = $ip.";".$info.";".$time."\n";

$fp = fopen($file, "a");

if(!fwrite($fp, $content[$j])) {
	echo '<strong>Fehler! Bitte den Admin kontaktieren!<br/><a href="mailto:root@flexmex.net">Flex</a></strong>';
} else {
	

	/*/
Download a file using fpassthru()
/*/
$fileDir = "/var/www/vhosts/flexmex.net/subdomains/tiarna/movie"; // supply a path name.
$fileName = $movie; // supply a file name.
$fileString=$fileDir.'/'.$fileName; // combine the path and file
// translate file name properly for Internet Explorer.
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){
	$fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
}
// make sure the file exists before sending headers
if(!$fdl=@fopen($fileString,'r')){
	die("Cannot Open File!");
} else {
	header("Cache-Control: ");// leave blank to avoid IE errors
	header("Pragma: ");// leave blank to avoid IE errors
	header("Content-type: application/octet-stream");
	header("Content-Disposition: attachment; filename=\"".$fileName."\"");
	header("Content-length:".(string)(filesize($fileString)));
   sleep(1);
   fpassthru($fdl);
}

}
?>
 
Zurück