Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    216

    problema script che forza il download

    Salve,
    ho un problema con uno script che forza il download di un file;
    il file viene scaricato ma quando vado ad aprirlo mi dice "Inaspettata fine dell'archivio".
    Potete aiutarmi?
    Questo è il codice:
    Codice PHP:
        $file "download/myfile.rar";
        
    $file_mostrato "myfile.rar";

        
    header("Content-Type: application/rar");
        
    header("Cache-Control: public");
        
    header("Content-Description: File Transfer");
        
    header("Content-Disposition: attachment; filename=".$file_mostrato);
        
    header("Content-Transfer-Encoding: binary");
        
    header("Content-Length: " filesize($file));
        
    readfile($file); 

  2. #2
    Provato in locale e funziona.
    "Mai discutere con un idiota. Ti trascina al suo livello e ti batte con l'esperienza." (Oscar Wilde)

  3. #3
    io uso questo codice e mi trovo molto bene
    Codice PHP:
    <?php

    // place this code inside a php file and call it f.e. "download.php"
    $path $_SERVER['DOCUMENT_ROOT']."/"// change the path to fit your websites document structure
    $fullPath $path.$_GET['download_file'];

    if (
    $fd fopen ($fullPath"r")) {
        
    $fsize filesize($fullPath);
        
    $path_parts pathinfo($fullPath);
        
    $ext strtolower($path_parts["extension"]);
        switch (
    $ext) {
            case 
    "pdf":
            
    header("Content-type: application/pdf"); // add here more headers for diff. extensions
            
    header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
            
    break;
            default;
            
    header("Content-type: application/octet-stream");
            
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
        }
        
    header("Content-length: $fsize");
        
    header("Cache-control: private"); //use this to open files directly
        
    while(!feof($fd)) {
            
    $buffer fread($fd2048);
            echo 
    $buffer;
        }
    }
    fclose ($fd);
    exit;

    ?>
    e poi per scaricare il file usi download.php?download_file=download/myfile.rar

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.