Просмотр файла avatar/index.php

Размер файла: 4.1Kb
  1. <?
  2. /*
  3. =============================================
  4. Движок: SHCMS Engine
  5. =============================================
  6. Название файла: Установка аватара
  7. =============================================
  8. Official website: http://shcms.ru
  9. =============================================
  10. */
  11. define('SHCMS', true);
  12. include_once'../system/inc/basic_settings.php';
  13. $shcmsengine['title'] = 'Установка аватара';
  14. include_once'../template/head.php';registrat();
  15. $user4 = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE id=$user_id"));
  16.  
  17.  
  18.  
  19. if(isset($_POST['submit']))
  20. {
  21. $submit = $_POST['submit'];
  22. }
  23. if(isset($submit))
  24. {
  25.  
  26. $file_avatar = '../avatar/files/'; // папка с аватарами
  27.  
  28.  
  29. if(!empty($_FILES['image']))
  30. {
  31. if($_FILES['image']['error'])
  32. {
  33. echo '<div class="errors">Ошибка при выгрузке</div>';
  34. header("Refresh: 1; url=?");
  35. include_once'../template/foot.php';
  36. exit();
  37. }
  38. if(!$_FILES['image']['size'])
  39. {
  40. echo '<div class="errors">Содержимое файла пустое</div>';
  41. header("Refresh: 1; url=?");
  42. include_once'../template/foot.php';
  43. exit();
  44. }
  45. if(!preg_match('#\.jpe?g$#ui', $_FILES ['image']['name']) and !preg_match('#\.gif$#ui',$_FILES['image']['name']))
  46. {
  47. echo '<div class="errors">Неверное содержание файла</div>';
  48. header("Refresh: 1; url=?");
  49. include_once'../template/foot.php';
  50. exit();
  51. }
  52. if(!$img = @imagecreatefromjpeg($_FILES ['image'] ['tmp_name']) and !$img = imagecreatefromgif($_FILES['image']['tmp_name']))
  53. {
  54. echo '<div class="errors">Файл не является изображением JPEG или GIF</div>';
  55. header("Refresh: 1; url=?");
  56. include_once'../template/foot.php';
  57. exit();
  58. }
  59. if((@imagesx($img) < 130))
  60. {
  61. echo '<div class="errors">Ширина изобожения должно быть больше 130px</div>';
  62. header("Refresh: 1; url=?");
  63. include_once'../template/foot.php';
  64. exit();
  65. }
  66. if((@imagesy($img) < 130))
  67. {
  68. echo '<div class="errors">Ширина изобожения должно быть больше 130px</div>';
  69. header("Refresh: 1; url=?");
  70. include_once'../template/foot.php';
  71. exit();
  72. }
  73. }
  74. $handle = new upload($_FILES['image']);
  75. if ($handle->uploaded) {
  76. $handle->file_new_name_body = $user_id;
  77. $handle->allowed = array('image/jpeg', 'image/gif');
  78. $handle->file_overwrite = true;
  79. $handle->image_convert = 'jpg';
  80. $handle->image_resize = true;
  81. if($_POST['amount'] == 1)
  82. {
  83. $handle->image_y = 130;
  84. $handle->image_x = 130;
  85. }elseif($_POST['amount'] == 2)
  86. {
  87. $handle->image_y = 180;
  88. $handle->image_x = 180;
  89. }elseif($_POST['amount'] == 3)
  90. {
  91. $handle->image_y = 220;
  92. $handle->image_x = 220;
  93. }elseif($_POST['amount'] == 4)
  94. {
  95. $handle->image_y = 300;
  96. $handle->image_x = 300;
  97. }
  98. $handle->process("$file_avatar");
  99. if ($handle->processed) {
  100. echo '<div class="actshcms">Аватар успешно установлен</div>';
  101. }
  102. else {
  103. echo display_error($handle->error);
  104. }
  105. $handle->clean();
  106. }
  107.  
  108.  
  109.  
  110.  
  111. }
  112. if(is_file('../avatar/files/'.$user_id.'.jpg'))
  113. {
  114. echo '<img class="image_avatar" src="../avatar/files/'.$user_id.'.jpg"/><br/>';
  115. }
  116. $images_amount = array(1=>'130x130',2=>'180x180',3=>'220x220',4=>'300x300');
  117. echo 'Файл аватара(.gif и .jpg)<br/>';
  118. echo '<form enctype="multipart/form-data" action="?'.$conservation.'" method="post">';
  119. echo "<input accept='image/*,image/gif,image/jpeg' type='file' name='image'/>";
  120. echo '<br/>Выбор размера аватара:<br/><select name="amount">';
  121. echo "<option selected>{$images_amount[$_POST[amount]]}";
  122. echo '<option value="1">130x130</option>';
  123. echo '<option value="2">180x180</option>';
  124. echo '<option value="3">220x220</option>';
  125. echo '<option value="4">300x300</option>';
  126. echo '</option></select>';
  127. if(!is_file('../avatar/files/'.$user_id.'.jpg'))
  128. {echo '<br/><input type="submit" value="Установить" name="submit"/>';}
  129. else{echo '<br/><input type="submit" value="Заменить" name="submit"/>';}
  130. echo '</form>';
  131. include_once'../template/foot.php';
  132. ?>