3 private $type = array("jpg","jpeg","gif","png"),$width = 250,$height = 250,$info = '',$error='';
4 function __construct($file,$dir,$newfile){
7 $this->newfile = $newfile;
10 public function upload(){
11 $ext = explode(".",$this->file['name']);
12 $ext = strtolower(end($ext));
14 if(file_exists($this->dir.$this->file['name'])){
15 $this->error .= "<div class='text-center'><b>Filename alredy exist!</b></div>";
18 if (!in_array($ext,$this->type)){
19 $this->error .= "<div class='text-center'><b>File Format not supported</b></div>";
22 list($imwidth,$imheight) = @getimagesize($this->file['tmp_name']);
24 $hx = (100 / ($imwidth / $this->width)) * .01;
25 $hx = round ($imheight * $hx);
27 if ($hx < $this->height) {
28 $this->height = (100 / ($imwidth / $this->width)) * .01;
29 $this->height = round ($imheight * $this->height);
31 $this->width = (100 / ($imheight / $this->height)) * .01;
32 $this->width = round ($imwidth * $this->width);
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']);
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>";
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);
60 public function getInfo(){
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>";}
70 public static function e($e)