Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Download pdf

  1. #1
    Utente di HTML.it L'avatar di buji
    Registrato dal
    Nov 2002
    Messaggi
    178

    Download pdf

    Buongiorno,
    mi trovo a dover fare una funzioncina di download di un file pdf.
    Premetto che non conosco assolutamente nulla di php (e prometto che mi applicherò per colmare questa lacuna il prima possibile).
    Spulciando nel forum ho trovato questa funzione:
    codice:
    <?
    function forceDownload( &$file ) {
    if( file_exists( $file ) == true && is_readable( $file ) == true ) {
    $filename = &basename( $file );
    if( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
    $parsename = &explode( '.', $filename );
    $last = count( $parsename ) - 1;
    $filename = &implode( '%2E', array_slice( $parsename, 0, $last ) );
    $filename .= '.'.$parsename[$last];
    }
    $content = &file_get_contents( $file );
    header( 'Content-Type: application/octet-stream' );
    header( 'Content-Disposition: attachment; filename='.$filename );
    header( 'Content-Length:'.strlen( $content ) );
    header( 'Content-Transfer-Encoding: binary' );
    echo $content;
    exit(0);
    }
    }
    $file = 'catalogo.pdf';
    forceDownload( $file );
    ?>
    L'ho testata ma mi da una sequenza di errori di questo tipo:
    Cannot modify header information - headers already sent by mio percorso.
    Di che si tratta?
    Grazie in anticipo...
    Buji

  2. #2
    Utente di HTML.it L'avatar di buji
    Registrato dal
    Nov 2002
    Messaggi
    178
    Scusate... Risolto!
    Sono rintronato...
    Buji

  3. #3
    la funzione e' questa:
    http://www.devpro.it/code/72.html

    e sei pregato di rimettere i credits / commenti , come da licenza, grazie
    Formaldehyde a new Ajax PHP Zero Config Error Debugger

    WebReflection @WebReflection

  4. #4
    Ora si che ci siamo..

    Codice PHP:

    function forceDownload( &$file ) {
        
    /**
         * Function forceDownload:
         *    download any type of file if it exists and is readable
         * -------------------------------------
         * @author        Andrea Giammarchi
         * @date        18/01/2005 [13/04/2005]
         * @compatibility    PHP >= 4.3.0
         */
        
    if( file_exists$file ) == true && is_readable$file ) == true ) {
            
    $filename = &basename$file );
            if( 
    strpos$_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
                
    $parsename = &explode'.'$filename );
                
    $last count$parsename ) - 1;
                
    $filename = &implode'%2E'array_slice$parsename0$last ) );
                
    $filename .= '.'.$parsename[$last];
            }
            
    $content = &file_get_contents$file );
            
    header'Content-Type: application/octet-stream' );
            
    header'Content-Disposition: attachment; filename="'.$filename.'"' );
            
    header'Content-Length:'.strlen$content ) );
            
    header'Content-Transfer-Encoding: binary' );
            echo 
    $content;
            exit(
    0);
        }


    Andr3a sei grande!!!!!
    3/6/2003 è morto l'angelo della mia vita..
    www.markwebinformatica.net
    My BLOG

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.