Guest User

Untitled

a guest
May 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. <?
  2. class Upload {
  3. private $filesize,$upload,$path;
  4.  
  5. function __construct($filesize,$upload,$path) {
  6. $this->filesize = $filesize;
  7. $this->upload = $upload;
  8. $this->path = $path;
  9. $this->source = $source;
  10. }
  11. function calcImage($image) {
  12.  
  13. }
  14.  
  15. function uploadImage($maxHeight = '',$maxWidth = '') {
  16. if($this->upload['size'] < $this->filesize && !$this->upload['error']) {
  17. $this->path = $this->path . substr(hash('sha512', uniqid(rand(), true)), 0, 6) . strtolower(preg_replace('/[^0-9A-Za-z.]/i', '', basename($this->upload['name'])));
  18.  
  19. if(@move_uploaded_file($this->upload['tmp_name'], $this->path)) {
  20. if($maxHeight && $maxWidth) {
  21. switch($this->upload['type']) {
  22. case 'image/png':
  23. $this->source = imagecreatefrompng($this->path);
  24. break;
  25. case 'image/jpeg':
  26. $this->source = imagecreatefromjpeg($this->path);
  27. break;
  28. case 'image/gif':
  29. $this->source = imagecreatefromgif($this->path);
  30. break;
  31. }
  32.  
  33. list($width, $height) = getimagesize($this->path);
  34. $xRatio = $maxWidth / $width;
  35. $yRatio = $maxHeight / $height;
  36.  
  37. if (($width <= $maxWidth) && ($height <= $maxHeight)) {
  38. $newWidth = $width;
  39. $newHeight = $height;
  40. }
  41.  
  42. elseif (($xRatio * $height) < $maxHeight) {
  43. $newHeight = ceil($xRatio * $height);
  44. $newWidth = $maxWidth;
  45. }
  46.  
  47. else {
  48. $newWidth = ceil($yRatio * $width);
  49. $newHeight = $maxHeight;
  50. }
  51.  
  52. $tmp = imagecreatetruecolor($newWidth, $newHeight);
  53. imagecopyresampled($tmp, $this->source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
  54.  
  55. if(@unlink($this->path)) {
  56. imagejpeg($tmp, $this->path, 100);
  57. imagedestroy($this->source);
  58. imagedestroy($tmp);
  59. }
  60. }
  61.  
  62. return $this->path;
  63. }
  64. }
  65. }
  66. }
  67. ?>
Add Comment
Please, Sign In to add comment