retorno url link subida
[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  $this->info .= "<div class='text-center'><b>Subido correctamente<br></b></div>Link: <a href='https://reisub.nsupdate.info/imagebin/upload/index.php?pic=".$this->newfile."'>Mi imagen subida</a>";
46  }
47
48  if($ext == "jpg" || $ext == "jpeg") {
49  @imagejpeg($image, $this->dir.$this->newfile, 100);
50  } else if($ext == "gif") {
51  @imagegif ($image, $this->dir.$this->newfile);
52  } else if($ext == "png") {
53  @imagepng ($image, $this->dir.$this->newfile, 0);
54  }
55  
56  @imagedestroy($im);
57  return $im;
58  
59  }
60  
61  public function getInfo(){
62  return $this->info;
63  }
64  
65  public function getError(){
66  if(empty($this->error))
67  {$this->error = "<div class='text-center'><b>Unknown error! Your request cannot complete now!</b></div>";}
68  return $this->error;
69  }
70  
71  public static function e($e)
72  {
73  echo $e;
74  }
75  
76 }
77 ?>