Initial commit
[imagebin.git/.git] / upload.class_HD.php
1 <?php 
2 class uploader{
3 private $type = array("jpg","jpeg","gif","png"),$width = 1366,$height = 768,$info = '',$error='';
4  function __construct($file,$dir,$newfile){
5  $this->file = $file;
6  $this->dir = $dir;
7  $this->newfile = $newfile;
8  @error_reporting(0);
9  }
10  public function upload(){
11  $ext = explode(".",$this->file['name']);
12  $ext = strtolower(end($ext));
13  
14  if(file_exists($this->dir.$this->file['name'])){
15  $this->error .= "<div class='text-center'><b>Filename alredy exist!</b></div>";
16  return false;
17  }
18  if (!in_array($ext,$this->type)){
19  $this->error .= "<div class='text-center'><b>File Format not supported</b></div>";
20  return false;
21  }
22  list($imwidth,$imheight) = @getimagesize($this->file['tmp_name']);
23  
24  $hx = (100 / ($imwidth / $this->width)) * .01;
25  $hx = round ($imheight * $hx);
26  
27  if ($hx < $this->height) {
28  $this->height = (100 / ($imwidth / $this->width)) * .01;
29  $this->height = round ($imheight * $this->height);
30  } else {
31  $this->width = (100 / ($imheight / $this->height)) * .01;
32  $this->width = round ($imwidth * $this->width);
33  }
34  $image = @imagecreatetruecolor($this->width, $this->height);
35  if($ext == "jpg" || $ext == "jpeg") {
36  $im = @imagecreatefromjpeg ($this->file['tmp_name']);
37  } else if($ext == "gif") {
38  $im = @imagecreatefromgif ($this->file['tmp_name']);
39  } else if($ext == "png") {
40  $im = @imagecreatefrompng ($this->file['tmp_name']);
41  }
42  
43  if(@imagecopyresampled($image, $im, 0, 0, 0, 0, $this->width, $this->height, $imwidth, $imheight)){
44  $this->info .= "<div class='text-center'><b>Image uploded successfully!</b></div>";
45  }
46
47  if($ext == "jpg" || $ext == "jpeg") {
48  @imagejpeg($image, $this->dir.$this->newfile, 100);
49  } else if($ext == "gif") {
50  @imagegif ($image, $this->dir.$this->newfile);
51  } else if($ext == "png") {
52  @imagepng ($image, $this->dir.$this->newfile, 0);
53  }
54  
55  @imagedestroy($im);
56  return $im;
57  
58  }
59  
60  public function getInfo(){
61  return $this->info;
62  }
63  
64  public function getError(){
65  if(empty($this->error))
66  {$this->error = "<div class='text-center'><b>Unknown error! Your request cannot complete now!</b></div>";}
67  return $this->error;
68  }
69  
70  public static function e($e)
71  {
72  echo $e;
73  }
74  
75 }
76 ?>