Bonjour
J'essaie de mettre en place un script PHP qui permet de télécharger des fichiers de plus de 20Mo.
Voici le script :
<?php
@ob_end_clean();
@ini_set("zlib.output_compression", "Off" );
$filename = $_GET["str"];
function dl_file_resume($file){
if (!is_file($file)) { die("<b>404 File not found!</b>" ); }
$len = filesize($file);
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"." ),1));
switch( $file_extension ) {
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "mp3": $ctype="audio/mpeg"; break;
case "mpg":$ctype="video/mpeg"; break;
case "avi": $ctype="video/x-msvideo"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "php":
case "htm":
case "html":
case "txt": die("<b>Cannot be used for ". $file_extension ." files!</b>" ); break;
default: $ctype="application/force-download";
}
header("Cache-Control:" );
header("Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0" );
header("Content-Description: File Transfer" );
header("Content-Transfer-Encoding: none" );
header("Content-Type: $ctype" );
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Accept-Ranges: bytes" );
$size=filesize($file);
if(isset($_SERVER['HTTP_RANGE'])) {
list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
str_replace($range, "-", $range);
$size2=$size-1;
$new_length=$size2-$range;
header("HTTP/1.1 206 Partial Content" );
header("Content-Length: $new_length" );
header("Content-Range: bytes $range$size2/$size" );
} else {
$size2=$size-1;
header("Content-Range: bytes 0-$size2/$size" );
header("Content-Length: ".$size2);
}
if ($file = fopen($file, 'rb')) {
while(!feof($file) and (connection_status()==0)) {
set_time_limit(9000);
print(fread($file, 1024*8));
flush();
}
fclose($file);
}
return((connection_status()==0) and !connection_aborted());
}
exit;
}
if (dl_file_resume($filename)){
die ("file transfer failed" );
} else {
}
?>
J'appelle le telechargement par : http://toto.fr/index.php?srt=Monnomdefichier.ppt
Le probleme est quoi que je fasse, quoi que j'ecrive le fichier se télécharge mais jamais en entier. Il se coupe aleatoirement 13Mo, 12, 14Mo...
Une idée ? un script magique ?
Merci d'avance.
Message édité par orlith le 13-04-2006 à 15:24:57