예제 #1
0
 function __construct($path, $thumb_img_resize_width = "200")
 {
     $answer = NULL;
     $this->dir = $path;
     $result_files = array();
     foreach ($_FILES as $key => $value) {
         $path_parts = pathinfo($value['name']);
         $extension = $path_parts['extension'];
         //$new_name_file = 'img_' . time() . '.' . $extension;
         $new_name_file = $value['name'];
         if (!file_exists($this->dir)) {
             mkdir($this->dir);
         }
         //Картинки
         if ($extension == "jpg" || $extension == "jpeg" || $extension == "gif" || $extension == "png") {
             if (file_exists($this->dir . $value['name'])) {
                 $answer .= $value['name'] . " ";
             } else {
                 //Размер изображения
                 move_uploaded_file($value['tmp_name'], $this->dir . $new_name_file);
                 //echo $this -> dir . "/" . $new_name_file;
                 //print_r($_FILES);
                 if (!file_exists($this->dir . 'thumb/')) {
                     mkdir($this->dir . 'thumb/');
                 }
                 $new_image = new SimpleImage($this->dir . $new_name_file);
                 $new_image->imageresizewidth($thumb_img_resize_width);
                 $new_image->imagesave($new_image->image_type, $this->dir . 'thumb/' . $new_name_file);
                 $new_image->imageout();
                 //array_push($result_files, $new_name_file);
             }
         } else {
             if (file_exists($this->dir . $value['name'])) {
                 $answer .= $value['name'] . " ";
             } else {
                 //Размер изображения
                 move_uploaded_file($value['tmp_name'], $this->dir . $new_name_file);
                 //array_push($result_files, $new_name_file);
             }
         }
         sleep(1);
     }
     echo "ok";
     exit;
 }