Advertisement
teague

Untitled

Jun 13th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL & ~E_NOTICE);
  4. require_once('mysql/mysql.class.php');
  5. require_once('rskmorph.php');
  6. require_once('marathon.php');
  7. require_once('lines_config.php');
  8. define(DOMAIN_PREFIX, '/rsklines/');
  9. define(IMAGE_PATH, 'images/');
  10. define(MAIN_TEXT_FONT_SIZE, 10);
  11.  
  12. if (isset($_FILES['add_image']) && !empty($_FILES['add_image']))
  13. {
  14.  
  15. $name = current($_FILES['add_image']['name']);
  16. $tmp_name = current($_FILES['add_image']['tmp_name']);
  17. $size = current($_FILES['add_image']['size']);
  18. $type = current($_FILES['add_image']['type']);
  19. $error = current($_FILES['add_image']['error']);
  20. $file = array('name' => $name, 'tmp_name' => $tmp_name, 'size' => $size, 'error' => $error, 'type' => $type);
  21. $mime = $file['type'];
  22. $size = $file['size'];
  23. if (!in_array($mime, array('image/gif', 'image/png', 'image/jpeg')))
  24. {
  25. die('Ошибка. Неправильный формат файла. Разрешаются gif, png, jpeg');
  26. }
  27. if ($size > 1024 * 1024 * 5)
  28. {
  29. die('Ошибка. Слишком большой файл. Разрешается загружать не больше 5 Мб ');
  30. }
  31. $pinfo = pathinfo($file['name'], PATHINFO_EXTENSION);
  32. $destination = 'uploads';
  33.  
  34. $new_fname_full = IMAGE_PATH . $file['name'];
  35. if (move_uploaded_file($file['tmp_name'], $new_fname_full))
  36. {
  37. echo $new_fname_full;
  38. }
  39. else
  40. {
  41. die('Ошибка. Не удалось скопировать файл');
  42. }
  43. }
  44. else
  45. {
  46. $row = $_REQUEST;
  47. $marathon = new Marathon();
  48. if (!empty($row['id']))
  49. {
  50. $marathon->loadMarathon($row['id']);
  51. $old_picture = $marathon->resulting_image;
  52. }
  53.  
  54. if (isset($_REQUEST['purpose']) && !empty($_REQUEST['purpose']) && !isset($_REQUEST['raw']) &&
  55. ('make_line' == $_REQUEST['purpose'] || 'refresh_line' == $_REQUEST['purpose']))
  56. {
  57. $marathon->loadFromArray($_POST);
  58. $marathon->id = $marathon->saveMarathon();
  59. if (!$marathon->id)
  60. {
  61. $marathon->getError();
  62. die('Ошибка сохранения');
  63. }
  64.  
  65. $image_wizard = new MarathonImageWizard($marathon);
  66. $marathon->resulting_image = $image_wizard->getImg();
  67. $marathon->saveMarathon();
  68. unset($marathon->dbconn);
  69. if (!empty($old_picture))
  70. {
  71. @unlink($old_picture);
  72. }
  73. echo json_encode($marathon);
  74. }
  75. if (isset($_REQUEST['purpose']) && !empty($_REQUEST['purpose']) && isset($_REQUEST['raw']))
  76. {
  77.  
  78. $image_wizard = new MarathonImageWizard($marathon);
  79. $marathon->resulting_image = $image_wizard->getImg();
  80. $marathon->saveMarathon();
  81. unset($marathon->dbconn);
  82. echo json_encode($marathon);
  83. if (isset($_GET['raw']))
  84. {
  85. ob_end_clean();
  86. ob_start();
  87. //echo $marathon->resulting_image;
  88. $im = imagecreatefrompng($marathon->resulting_image);
  89. $im_size = filesize($marathon->resulting_image);
  90. header('Content-Type: image/png');
  91. header('Cache-Control: max-age=600, must-revalidate');
  92. header('Content-Length: '.$im_size);
  93. imagepng($im);
  94. imagedestroy($im);
  95. ob_end_flush();
  96. }
  97. }
  98. }
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement