Posted By

markafa on 10/27/18


Tagged


Versions (?)

Eski Uploader


 / Published in: PHP
 

Eski uploader böyle bir ?eydi...

  1. <?php
  2. require '../konfigurasyon.php';
  3. require '../util/TextOps.php';
  4.  
  5. function clearSrcName($url) {
  6. $toDelete = './../';
  7. return str_replace($toDelete, URL, $url);
  8. }
  9.  
  10. function createThumbnail($pathToImage, $thumbOrActual = 'actual', $thumbWidth = 350) {
  11. $result = 'Hata';
  12. if (is_file($pathToImage)) {
  13. $info = pathinfo($pathToImage);
  14.  
  15. $extension = strtolower($info['extension']);
  16. if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
  17.  
  18. switch ($extension) {
  19. case 'jpg':
  20. $img = imagecreatefromjpeg("{$pathToImage}");
  21. break;
  22. case 'jpeg':
  23. $img = imagecreatefromjpeg("{$pathToImage}");
  24. break;
  25. case 'png':
  26. $img = imagecreatefrompng("{$pathToImage}");
  27. imagealphablending($img, true);
  28. break;
  29. case 'gif':
  30. $img = imagecreatefromgif("{$pathToImage}");
  31. break;
  32. default:
  33. $img = imagecreatefromjpeg("{$pathToImage}");
  34. }
  35. // load image and get image size
  36.  
  37. $width = imagesx($img);
  38. $height = imagesy($img);
  39.  
  40. // calculate thumbnail size
  41. $new_width = $thumbWidth;
  42. $new_height = floor($height * ( $thumbWidth / $width ));
  43.  
  44. // create a new temporary image
  45. $tmp_img = imagecreatetruecolor($new_width, $new_height);
  46.  
  47. // copy and resize old image into new image
  48. imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  49. $extLength = strlen($extension) + 1;
  50. if ($thumbOrActual == 'thumb') {
  51. $pathToImage = substr_replace($pathToImage, '', -$extLength) . '_thumb.' . $extension;
  52. } elseif ($thumbOrActual == 'actual') {
  53. $pathToImage = substr_replace($pathToImage, '', -$extLength) . '.' . $extension;
  54. }
  55. // save thumbnail into a file
  56. switch ($extension) {
  57. case 'jpg':
  58. imagejpeg($tmp_img, "{$pathToImage}", 60);
  59. break;
  60. case 'jpeg':
  61. imagejpeg($tmp_img, "{$pathToImage}", 60);
  62. break;
  63. case 'png':
  64. imagepng($tmp_img, "{$pathToImage}", 7);
  65. break;
  66. case 'gif':
  67. imagegif($tmp_img, "{$pathToImage}", 60);
  68. break;
  69. default:
  70. imagejpeg($tmp_img, "{$pathToImage}", 60);
  71. }
  72. $result = $pathToImage;
  73. } else {
  74. $result = 'Hata|Geçersiz bir resim dosyas? türü yüklemeye çal???yorsunuz! Lütfen JPG, PNG, GIF uzant?l? dosyalar yükleyiniz.';
  75. }
  76. } else {
  77. $result = 'Hata|Resim dosyas? yok.';
  78. }
  79. return $result;
  80. }
  81.  
  82. if ($_POST['image_form_submit'] == 1) {
  83. $images_arr = array();
  84. $cleaner = new TextOps();
  85. if (count($_FILES['file']['name']) < 11) {
  86. foreach ($_FILES['file']['name'] as $key => $val) {
  87. $image_name = $_FILES['file']['name'][$key];
  88. $tmp_name = $_FILES['file']['tmp_name'][$key];
  89. $size = $_FILES['file']['size'][$key];
  90. $type = $_FILES['file']['type'][$key];
  91. $error = $_FILES['file']['error'][$key];
  92.  
  93. ############ Remove comments if you want to upload and stored images into the "uploads/" folder #############
  94.  
  95. $target_dir = IMAGE_UPLOAD_DIRECTORY;
  96. $fileToRename = $_FILES['file']['name'][$key];
  97. $newFileName = $cleaner->fileConv($fileToRename);
  98.  
  99. $target_file = $target_dir . $newFileName;
  100.  
  101. if (move_uploaded_file($_FILES['file']['tmp_name'][$key], $target_file)) {
  102. $images_arr[] = $target_file;
  103. }
  104.  
  105. /**
  106.   * Resize image starts here
  107.   */
  108. $resultThumb = explode('|', createThumbnail($target_file, 'thumb', 350));
  109. if ($resultThumb[0] != 'Hata') {
  110.  
  111. } else {
  112. echo 'Küçük resim yarat?l?rken hata olu?tu<br />';
  113. }
  114. $resultActual = explode('|', createThumbnail($target_file, 'actual', 800));
  115. if ($resultActual[0] != 'Hata') {
  116.  
  117. } else {
  118. echo 'Resim yeniden boyutland?r?l?rken hata olu?tu<br />';
  119. }
  120. /**
  121.   * Resize image ends here
  122.   */
  123. }
  124.  
  125.  
  126. //Generate images view
  127. if (!empty($images_arr)) {
  128. $count = 0;
  129. echo '<ul>';
  130. foreach ($images_arr as $image_src) {
  131. $count++
  132. ?>
  133. <li><img src="<?php echo clearSrcName($image_src); ?>" alt=""><input type="hidden" value="<?php echo clearSrcName($image_src); ?>" name="ph<?= $count; ?>" id="ph<?= $count; ?>" /></li>
  134. <?php
  135. }
  136. echo '</ul>';
  137. }
  138. } else {
  139. echo 'Her ilan için en fazla 10 dosya yükleyebilirsiniz!';
  140. }
  141. }

Report this snippet  

You need to login to post a comment.