Ciao a tutti

ho uno script che ho trovato in rete che dovrebbe far comparire la maschera del browser per salvare o aprire il file che si sta scaricando senza aprirlo in automatico.


se salvo il file e lo apro dopo tutto ok ma se lo apro direttamente mi da errore per esempio l'acrobat reader che dovrebbe leggere il file

ecco lo script che sto provando



Codice PHP:

//header("Content-Type: $file_mime");
header('Content-type: application/pdf');
header("Content-Length: " filesize($file_path));
$agent $_SERVER["HTTP_USER_AGENT"];
if( 
is_int(strpos($agent"MSIE")) ){
    
# Remove reserved chars: :\/*?"<>|
    
$fn preg_replace('/[:\\x5c\\/*?"<>|]/''_'$file_name);
    
# Non-standard URL encoding:
    
header("Content-Disposition: attachment; filename="
    
rawurlencode($fn));
} else if( 
is_int(strpos($agent"Gecko")) ){
    
# RFC 2231:
    
header("Content-Disposition: attachment; filename*=UTF-8''"
    
rawurlencode($file_name));
} else if( 
is_int(strpos($agent"Opera")) ) {
    
# Remove reserved chars: :\/*{?
    
$fn preg_replace('/[:\\x5c\\/{?]/''_'$file_name);
    
# RFC 2231:
    
header("Content-Disposition: attachment; filename*=UTF-8''"
    
rawurlencode($fn));
} else {
    
# RFC 2616 ASCII-only encoding:
    
$fn mb_convert_encoding($file_name"US-ASCII""UTF-8");
    
$fn = (string) str_replace("\\""\\\\"$fn);
    
$fn = (string) str_replace("\"""\\\""$fn);
    
header("Content-Disposition: attachment; filename=\"$fn\"");
}
readfile($file_path);