phpDocumentor VFront
[ class tree: VFront ] [ index: VFront ] [ all elements ]

Source for file download.php

Documentation is available at download.php

  1. <?php
  2. /**
  3. * Script di download.
  4. * Attraverso questo script vengono processati i file allegati e spediti con un header di tipo attachment.
  5. * Qualora richiesto, viene creato un file .zip con pił allegati
  6. @package VFront
  7. @author Mario Marcello Verona <marcelloverona@gmail.com>
  8. @copyright 2007 Mario Marcello Verona
  9. @version 0.90
  10. @license http://www.gnu.org/licenses/gpl.html GNU Public License
  11. */
  12.  
  13.  
  14. include("./inc/conn.php");
  15. include("./inc/func.frontend.php");
  16.  
  17.  
  18. if(isset($_GET['type']&& $_GET['type']=='all'){
  19.     
  20.     require_once("./inc/EasyZIP.class.php");
  21.     
  22.     // PRENDI CON UNA QUERY TUTTI I FILES ED I NOMI
  23.     // deduce da un ID tutti gli altri
  24.     
  25.     $id_pilota = (int) str_replace(_BASE64_PASSFRASE,'',base64_decode($_GET['idr']));
  26.     
  27.     $sql="SELECT t1.codiceallegato, t1.nomefileall, ".concat_sintax("'allegati_',t1.tipoentita,t1.codiceentita").
  28.             FROM "._TABELLA_ALLEGATO." t1, "._TABELLA_ALLEGATO." t2
  29.             WHERE t2.codiceallegato=$id_pilota
  30.             AND t1.codiceentita=t2.codiceentita
  31.             AND t1.tipoentita=t2.tipoentita
  32.             ORDER BY nomefileall";
  33.     
  34.     $q=vmsql_query($sql,$link);
  35.     
  36.     $num_rows=vmsql_num_rows($q);
  37.     
  38.     // se ci sono errori
  39.     if($num_rows==0){
  40.         
  41.         echo "Errore, nessun file trovato";
  42.     }
  43.     
  44.     $dir=md5(rand());
  45.     
  46.     // creo la directory
  47.     mkdir(_PATH_ATTACHMENT."/tmp/$dir");
  48.     
  49.     $z new EasyZIP;
  50.      
  51.     chdir(_PATH_ATTACHMENT."/tmp/$dir/");
  52.     
  53.     // COPIA TUTTI I FILES in una tabella temporanea
  54.  
  55.     while($RS=vmsql_fetch_row($q)){
  56.         
  57.             
  58.         $test=@copy(_PATH_ATTACHMENT."/".$RS[0].".dat",$RS[1]);
  59.         
  60.         $z -> addFile($RS[1]);
  61.         
  62.         $nome_origine_all[]=$RS[1];
  63.         
  64.         $nome_zip=$RS[2];
  65.     }
  66.     
  67.     
  68.     
  69.     $z -> zipFile("../$nome_zip.zip");
  70.     
  71.     
  72.     
  73.     // elimino la directory
  74.     
  75.     for($k=0;$k<count($nome_origine_all);$k++){
  76.         unlink($nome_origine_all[$k]);
  77.     }
  78.     
  79.     chdir(dirname(__FILE__));
  80.     
  81.     rmdir(_PATH_ATTACHMENT."/tmp/$dir");
  82.  
  83.     if(file_exists(_PATH_ATTACHMENT."/tmp/$nome_zip.zip")){
  84.            header("Pragma: public");
  85.            header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  86.            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  87.            header("Cache-Control: private",false);
  88.            header("Content-Type: application/zip");
  89.            header('Content-Disposition: attachment; filename="'.$nome_zip.'.zip"');
  90.            header("Content-Transfer-Encoding: binary");
  91.            header('Content-Length: '.filesize(_PATH_ATTACHMENT."/tmp/$nome_zip.zip"    ));
  92.            set_time_limit(0);
  93.            @readfile(_PATH_ATTACHMENT."/tmp/$nome_zip.zip"OR die("<html><body OnLoad=\"javascript: alert('Nessun file trovato');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
  94.         
  95.            unlink(_PATH_ATTACHMENT."/tmp/$nome_zip.zip")
  96.        }
  97.     else{
  98.         die("<html><body onload=\"javascript: alert('Nessun file da scaricare!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
  99.     }
  100.  
  101.     
  102.     
  103.     exit;
  104.     
  105. }
  106. elseif(isset($_GET['f'])){
  107.  
  108.     $id_file = (int) str_replace(_BASE64_PASSFRASE,'',base64_decode($_GET['f']));
  109.  
  110.     $sql="SELECT codiceallegato, nomefileall
  111.             FROM "._TABELLA_ALLEGATO."
  112.             WHERE codiceallegato=$id_file
  113.             ";
  114.     
  115.     $q=vmsql_query($sql,$link);
  116.     $num_rows=vmsql_num_rows($q);
  117.     
  118.         
  119.     // se ci sono errori
  120.     if($num_rows==0){
  121.         
  122.         echo "Errore, nessun file trovato";
  123.         exit;
  124.     }
  125.     
  126.     $RS=vmsql_fetch_row($q);
  127.     
  128.     
  129.     
  130.  
  131.  
  132.     
  133.     
  134.  
  135.     $dir=md5(rand());
  136.     
  137.     // creo la directory
  138.     mkdir(_PATH_ATTACHMENT."/tmp/$dir");
  139.     
  140.     $file_originale=_PATH_ATTACHMENT."/tmp/$dir/".$RS[1];
  141.     
  142.  
  143.     
  144.     
  145.     $test=@copy(_PATH_ATTACHMENT."/".$RS[0].".dat",$file_originale);
  146.         
  147.     if(file_exists($file_originale)){
  148.            header("Pragma: public");
  149.            header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
  150.            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  151.            header("Cache-Control: private",false);
  152.            header("Content-Type: application/force-download");
  153.            header('Content-Disposition: attachment; filename="'.$RS[1].'"');
  154.            header("Content-Transfer-Encoding: binary");
  155.            header('Content-Length: '.filesize($file_originale));
  156.            set_time_limit(0);
  157.            @readfile($file_originaleOR die("<html><body OnLoad=\"javascript: alert('Nessun file trovato');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
  158.          
  159.        }       
  160.     else{
  161.         die("<html><body onload=\"javascript: alert('Nessun file da scaricare!');history.back();\" bgcolor=\"#F0F0F0\"></body></html>");
  162.     }
  163.  
  164.     unlink($file_originale);
  165.     rmdir(_PATH_ATTACHMENT."/tmp/$dir");
  166.  
  167. }
  168.  
  169.  
  170. ?>

Documentation generated on Sat, 22 Sep 2007 11:49:59 +0200 by phpDocumentor 1.4.0a2