io l'avrei scritta cosi':
Codice PHP:
<?php
function download ($nome, $path) {
if( $fp = @fopen( $path, "r" ) ) {
$size = filesize( $path );
if( $size > 0 ) {
$binary = fread ($fp, $size);
$nome = stripslashes( $nome );
if( strpos( $_SERVER['HTTP_USER_AGENT'], "Gecko" ) !== false ) {
$search = Array( 'Ä', 'Ë', 'Ï', 'Ö', 'Ü', 'ä', 'ë', 'ï', 'ö', 'ü' );
$replace = Array( 'A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u' );
$nome = str_replace( $search, $replace, $nome );
}
header("Pragma: public");
header("Cache-control: private");
header("Expires: 0");
header("Content-type: application/RFC822");
header("Content-type: octet/stream\n");
header("Content-transfer-encoding: binary\n");
header("Content-Disposition: attachment; filename=".$nome."\n");
header("Content-Length:".$size);
echo $binary;
}
fclose($fp);
}
exit( 0 );
}
// esempio
download ("bar.gif", "img/bar.gif");
?>