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

Размер файла: 4.21Kb
  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';
  15. registrat();
  16.  
  17.  
  18.  
  19. if(isset($_POST['submit']))
  20. {
  21. $submit = $_POST['submit'];
  22. }
  23. if(isset($submit))
  24. {
  25. if(!empty($_FILES['image']))
  26. {
  27. if($_FILES['image']['error'])
  28. {
  29. echo '<div class="errors">Ошибка при выгрузке</div>';
  30. header("Refresh: 1; url=?");
  31. include_once'../template/foot.php';
  32. exit();
  33. }
  34. if(!$_FILES['image']['size'])
  35. {
  36. echo '<div class="errors">Содержимое файла пустое</div>';
  37. header("Refresh: 1; url=?");
  38. include_once'../template/foot.php';
  39. exit();
  40. }
  41. if(!preg_match('#\.jpe?g$#ui', $_FILES ['image']['name']) and !preg_match('#\.gif$#ui',$_FILES['image']['name'])and !preg_match('#\.png$#ui',$_FILES['image']['name']))
  42. {
  43. echo '<div class="errors">Неверное содержание файла</div>';
  44. header("Refresh: 1; url=?");
  45. include_once'../template/foot.php';
  46. exit();
  47. }
  48. if(!$img = @imagecreatefromjpeg($_FILES ['image'] ['tmp_name']) and !$img = @imagecreatefrompng($_FILES ['image'] ['tmp_name']) and !$img = imagecreatefromgif($_FILES['image']['tmp_name']))
  49. {
  50. echo '<div class="errors">Файл не является изображением JPEG, PNG или GIF</div>';
  51. header("Refresh: 1; url=?");
  52. include_once'../template/foot.php';
  53. exit();
  54. }
  55. if((@imagesx($img) < 130))
  56. {
  57. echo '<div class="errors">Ширина изобожения должно быть больше 130px</div>';
  58. header("Refresh: 1; url=?");
  59. include_once'../template/foot.php';
  60. exit();
  61. }
  62. if((@imagesy($img) < 130))
  63. {
  64. echo '<div class="errors">Ширина изобожения должно быть больше 130px</div>';
  65. header("Refresh: 1; url=?");
  66. include_once'../template/foot.php';
  67. exit();
  68. }
  69. }
  70. function format($name) {
  71. $f1 = strrpos($name, ".");
  72. $f2 = substr($name, $f1 + 1, 999);
  73. $fname = strtolower($f2);
  74. return $fname;
  75. }
  76. $listing = format($_FILES['image']['name']);
  77. $uploaddir = $_SERVER['DOCUMENT_ROOT']."/avatar/files/";
  78. $uploaddir.=$user_id.'.jpg';
  79. if(move_uploaded_file($_FILES["image"]["tmp_name"], $uploaddir))
  80. {
  81. $screen = new screen_shcms($uploaddir);
  82. $screen->autoimageresize(640, 480);
  83. $screen->imagesave($new_image->image_type, $uploaddir);
  84. $screen->imageout();
  85. echo '<div class="actshcms">Аватар успешно загружен</div>';
  86. }
  87. else
  88. {
  89. echo '<div class="actshcms">Аватар не загружен</div>';
  90. }
  91. }
  92.  
  93. if(is_file('../avatar/files/'.$user_id.'.jpg')){
  94. echo '<div class="maintitle mainrazd">Ваш аватар</div><div class="maintext">';
  95. echo '<img class="image_avatar" src="../avatar/files/'.$user_id.'.jpg"/></div>';
  96. }else{
  97. echo '<div class="maintitle mainrazd">Аватар не загружен</div><div class="maintext">';
  98. errors('Вы еще не добавили аватар');
  99. echo '</div>';
  100. }
  101. echo '<div class="maintitle mainrazd">Загрузка аватара</div><div class="maintext">';
  102. echo 'Файл аватара<br/>';
  103. echo '<form enctype="multipart/form-data" action="?'.$conservation.'" method="post">';
  104. echo "<input accept='image/*,image/gif,image/jpeg,image/png' type='file' name='image'/>";;
  105. if(!is_file('../avatar/files/'.$user_id.'.jpg')) {
  106. echo '<br/><input type="submit" value="Установить" name="submit"/>';
  107. }
  108. else{
  109. echo '<br/><input type="submit" value="Заменить" name="submit"/>';
  110. }
  111. echo '</form></div>';
  112. include_once'../template/foot.php';
  113. ?>