Просмотр файла download/preview.php

Размер файла: 1.99Kb
  1. <?php
  2.  
  3. if (!isset($_GET['img']))
  4. exit;
  5. function format($name)
  6. {
  7. $f1 = strrpos($name, ".");
  8. $f2 = substr($name, $f1 + 1, 999);
  9. $fname = strtolower($f2);
  10. return $fname;
  11. }
  12. $type = isset($_GET['type']) ? abs(intval($_GET['type'])) : 0;
  13. $image = isset($_GET['img']) ? htmlspecialchars(urldecode($_GET['img'])) : null;
  14. if ($image && file_exists($image)) {
  15. $att_ext = strtolower(format($image));
  16. $pic_ext = array('gif', 'jpg', 'jpeg', 'png');
  17. if (in_array($att_ext, $pic_ext)) {
  18. $info_file = GetImageSize($image);
  19. $w_or = $info_file[0];
  20. $h_or = $info_file[1];
  21. $type_file = $info_file['mime'];
  22. switch ($type) {
  23. case 1:
  24. $w = 40;
  25. $h = 40;
  26. break;
  27. default:
  28. if ($w_or > 240) {
  29. $w = 240;
  30. $h = ceil($h_or / ($w_or / 240));
  31. }
  32. else {
  33. $w = $w_or;
  34. $h = $h_or;
  35. }
  36. }
  37. switch ($att_ext) {
  38. case "gif":
  39. $image_file = ImageCreateFromGIF($image);
  40. break;
  41. case "jpg":
  42. $image_file = ImageCreateFromJPEG($image);
  43. break;
  44. case "jpeg":
  45. $image_file = ImageCreateFromJPEG($image);
  46. break;
  47. case "png":
  48. $image_file = ImageCreateFromPNG($image);
  49. break;
  50. }
  51. $two_image = imagecreatetruecolor($w, $h);
  52. imagecopyresampled($two_image, $image_file, 0, 0, 0, 0, $w, $h, $w_or, $h_or);
  53. ob_start();
  54. imageJpeg($two_image, null, 60);
  55. ImageDestroy($image_file);
  56. imagedestroy($two_image);
  57. header("Content-Type: image/jpeg");
  58. header('Content-Disposition: inline; filename=preview.jpg');
  59. header('Content-Length: ' . ob_get_length());
  60. ob_end_flush();
  61. }
  62. }
  63.  
  64. ?>