Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. if( ! is_uploaded_file( $_FILES['imageUpload']['tmp_name']) || $_FILES['imageUpload']['error'] !== UPLOAD_ERR_OK) {
  2. echo "<p class='alert alert-danger text-danger font-size-16'>Selecione uma image para enviar.</p>";
  3. exit();
  4. }
  5.  
  6. $maxFileSize = 5242880;
  7. if($_FILES['imageUpload']['size'] > $maxFileSize) {
  8. echo "<p class="alert alert-danger text-danger font-size-16">Tamanho de arquivo maior do que o permitido.</p>";
  9. exit();
  10. }
  11. ##############################################
  12. if(is_array(getimagesize($_FILES["imageUpload"]["tmp_name"]))){
  13. $image_type_check = 'true';
  14. } else {
  15. $image_type_check = 'false';
  16. }
  17. if($image_type_check == 'false') {
  18. echo "<p class="alert alert-danger text-danger font-size-16">Formato de arquivo não permitido.</p>";
  19. exit();
  20. }
  21.  
  22. $filename = $_FILES['imageUpload']['name'];
  23. $location = "../arquivos/";
  24. $imagename = $_FILES['imageUpload']['name'];
  25. $source = $_FILES['imageUpload']['tmp_name'];
  26. $ext = explode( ".", $imagename );
  27. $ext = end( $ext );
  28. $nN = md5( $filename );
  29. $nN = time() . $nN;
  30. $novo_nome = $nN . "." . $ext;
  31. $target = $location . $novo_nome;
  32.  
  33. $image_info = getimagesize($_FILES["imageUpload"]["tmp_name"]);
  34. $image_width = $image_info[0];
  35. $image_height = $image_info[1];
  36.  
  37. if($image_width>800) {
  38. move_uploaded_file($source, $target);
  39. $imagepath = $novo_nome;
  40. $save = $location . $imagepath;
  41. $file = $location . $imagepath;
  42. list($width, $height) = getimagesize($file) ;
  43. $modwidth = 800;
  44. $diff = $width / $modwidth;
  45. $modheight = $height / $diff;
  46. $tn = imagecreatetruecolor($modwidth, $modheight) ;
  47. $image = imagecreatefromjpeg($file) ;
  48. imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
  49. imagejpeg($tn, $save, 72);
  50. } else if($image_width<800) {
  51. move_uploaded_file( $source, $target );
  52. $imagepath = $novo_nome;
  53. $save = $location . $imagepath;
  54. $file = $location . $imagepath;
  55. list($width, $height) = getimagesize($file) ;
  56. $modwidth = $image_width;
  57. $diff = $width / $modwidth;
  58. $modheight = $height / $diff;
  59. $tn = imagecreatetruecolor($modwidth, $modheight) ;
  60. $image = imagecreatefromjpeg($file) ;
  61. imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
  62. imagejpeg($tn, $save, 72);
  63. }
  64.  
  65. Array
  66. (
  67. [0] => nota-12809312-001.jpg
  68. [1] => nota-74831223-004.png
  69. [2] =>
  70. [3] =>
  71. [4] =>
  72. [5] =>
  73. [6] =>
  74. [7] =>
  75. [8] =>
  76. [9] =>
  77. [10] =>
  78. [11] =>
  79. )
  80.  
  81. $count = count( $_FILES['imageUpload']['name'] );
  82.  
  83. if( $count == 0 ) {
  84. echo "<p class="alert alert-danger text-danger font-size-16">Selecione uma imagem para o anúncio.</p>";
  85. exit();
  86. }
  87.  
  88. #### UPLOAD DAS IMAGENS
  89. $maxFileSize = 5242880;
  90. $imgError = 0;
  91. $imgErrorFile = array();
  92. $uploadSuccess = 0;
  93.  
  94. for( $x=1;$x<=$count;$x++ ) {
  95. if(is_array(getimagesize($_FILES["imageUpload"]["tmp_name"][$x]))){
  96. $image_type_check = 'true';
  97. } else {
  98. $image_type_check = 'false';
  99. }
  100. if($image_type_check == 'false') {
  101. echo "<p class="alert alert-danger text-danger font-size-16">Formato de arquivo não permitido.</p>";
  102. exit();
  103. }
  104. if( $_FILES['imageUpload']['size'][$x] > $maxFileSize ) {
  105. echo "<p class="alert alert-danger text-danger font-size-16">Tamanho de arquivo maior do que o permitido.</p>";
  106. exit();
  107. }
  108.  
  109. $count = count( $_FILES['imageUpload']['name'] );
  110.  
  111. if( $count == 0 ) {
  112. echo "<p class="alert alert-danger text-danger font-size-16">Selecione uma imagem para o anúncio.</p>";
  113. exit();
  114. }
  115.  
  116. $maxFileSize = 5242880;
  117.  
  118. for( $x=0;$x<$count;$x++ ) {
  119. if(is_array(getimagesize($_FILES["imageUpload"]["tmp_name"][$x]))){
  120. $image_type_check = 'true';
  121. } else {
  122. $image_type_check = 'false';
  123. }
  124. if($image_type_check == 'false') {
  125. echo "<p class="alert alert-danger text-danger font-size-16">Formato de arquivo não permitido.</p>";
  126. exit();
  127. }
  128. if( $_FILES['imageUpload']['size'][$x] > $maxFileSize ) {
  129. echo "<p class="alert alert-danger text-danger font-size-16">Tamanho de arquivo maior do que o permitido.</p>";
  130. exit();
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement