• User Newbie

    Problema con il download di un file pdf

    Salve,
    sono nuovo e non so bene come funziona.
    Ho un problema con il download di un file pdf
    con uno script in PHP, e mi serviva un aiuto.
    Sono nel posto giusto....


  • User

    Ciao, dovresti descrivere il problema e postare eventualmente il codice utilizzato per ricevere qualche aiuto.


  • User Newbie

    Lo script che utilizzo è il seguente:
    [php]<?php
    $file_name = "2005.pdf"; # file name, UTF-8 encoded
    $file_mime = "application/pdf"; # MIME type
    $file_path = "portaldata/UserFiles/File/2005.pdf";
    header("Content-Type: octet-stream");
    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);

    ?>[/php]

    Il problema che il file pdf (creto con INdesign) è di 22 Mega
    e sembra non riesco a fare il download di file superiori a 3 Mega.


  • User

    Sarebbe meglio se riportassi esattamente l'errore cosi come viene presentato nel browser, magari si tratta di un semplice timeout date le dimensioni del file,
    prova ad inserire come prima istruzione

    
    set_time_limit(600); // equivale a 10 minuti 
    
    

  • User Newbie

    Ho provato ad inserire il codice che mi hai postato,
    ma non ho risolto.
    Non mi dà errore, ma nella mascherina che mi si apre,
    dove mi chiede se voglio salvare o aprire il file, non mi segnala
    la dimensione del file.
    E' come se legesse 0 KB.
    Con un file più piccolo (3,77 Mega) funziona tutto, anche se poi, aprendolo e scorrendo le varie pagine, mi dà un errore di disegno.
    Grazie