Force Download — Gyural


/ Published in: PHP
Save to your folder(s)

test


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. isGyu();
  4. MethodStandard();
  5. Right('*');
  6.  
  7. $informazioni = CallFunction('mediateca', 'get', $_GET["id"]);
  8.  
  9. $prodotto = $informazioni->getAttr('prodotto');
  10.  
  11. // L'utente, ha acquistato questo prodotto?
  12. $carrelliValidi = CallFunction('acquisti', 'list');
  13. foreach($carrelliValidi as $v)
  14. if($v->getAttr('stato') >= 4)
  15. $validCart[] = "carrelloId = '" . FetchObject(Database()->query("SELECT * FROM `carrelli` WHERE acquistoId = '".$v->getAttr('id')."' LIMIT 1"), 0)->getAttr('id')."'";
  16.  
  17.  
  18. $q = "SELECT * FROM `carrelliItem` WHERE prodottoId = '".$informazioni->getAttr('prodotto')."' AND (" . implode(' OR ', $validCart) . ") LIMIT 1";
  19.  
  20. $informazioni_2 = FetchObject(Database()->query($q), 0);
  21.  
  22. if(is_object($informazioni_2)) {
  23.  
  24. $filename = upload . $informazioni->getAttr('contenuto');
  25.  
  26. $porzioni = explode(".", basename($filename));
  27. $ext = $porzioni[count($porzioni) - 1];
  28.  
  29. header("Pragma: public");
  30. header("Expires: 0"); // set expiration time
  31. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  32. // browser must download file from server instead of cache
  33.  
  34. // force download dialog
  35. header("Content-Type: application/force-download");
  36. header("Content-Type: application/octet-stream");
  37. header("Content-Type: application/download");
  38.  
  39. // use the Content-Disposition header to supply a recommended filename and
  40. // force the browser to display the save dialog.
  41. header("Content-Disposition: attachment; filename=".$informazioni->getAttr('nome') . "." . $ext .";");
  42.  
  43. header("Content-Transfer-Encoding: binary");
  44. header("Content-Length: ".filesize($filename));
  45.  
  46. @readfile($filename);
  47.  
  48. }
  49.  
  50. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.