aznim

Image file download

Sep 1st, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2. //könyvtár public ("frontend") mappával párhuzamos ("upload") mappa elérési útja
  3. $upload = str_replace("frontend", "", $_SERVER['DOCUMENT_ROOT']) . "upload/";
  4.  
  5. //kép fájl megnyitás adatbázisban tárolt elemek alapján
  6. include_once 'dbconnect.php';
  7. $iid = $_GET['iid'];
  8.  
  9. $sql=new ownedsql;
  10. $sql->connect();
  11. $sql->query("SELECT iPath, iFile FROM 3i_rest_images WHERE iid='$iid' AND iActive='1'");
  12. $result = $sql->query;
  13. $sql->kill();
  14.  
  15. $result = mysql_fetch_array($result);
  16.  
  17. $fullPath = $result['iPath'] . $result['iFile'];
  18.  
  19.  
  20. if ($fd = fopen($fullPath, "r")) {
  21.     $fsize = filesize($fullPath);
  22.     $path_parts = pathinfo($fullPath);
  23.     $ext = strtolower($path_parts["extension"]);
  24.     switch ($ext) {
  25.         case "jpg":
  26.             header("Content-type: image/jpeg");
  27.             header("Content-Disposition: filename=\"" . $path_parts["basename"] . "\"");
  28.             break;
  29.         default;
  30.             header("Content-type: application/octet-stream");
  31.             header("Content-Disposition: filename=\"" . $path_parts["basename"] . "\"");
  32.     }
  33.     header("Content-length: $fsize");
  34.     header("Cache-control: private");
  35.     while (!feof($fd)) {
  36.         $buffer = fread($fd, 2048);
  37.         echo $buffer;
  38.     }
  39. }
  40. fclose($fd);
  41. exit;
  42. ?>
Add Comment
Please, Sign In to add comment