Esempio n. 1
0
 public function actionUpload()
 {
     if (isset($_FILES['files']) && $_FILES['files']) {
         require Yii::app()->basePath . '/components/upload.class.php';
         $handle = new upload($_FILES['files']);
         $img_arr = array();
         $file_info = AFunction::generate_file_name('news');
         $_filename = $file_info['name'];
         $_filepath = realpath(Yii::app()->getBasePath() . '/../uploads/') . "/" . $file_info['physical_path'];
         if ($handle->uploaded) {
             //check extension
             if (!in_array($handle->file_src_name_ext, array('gif', 'jpg', 'jpeg', 'pjpeg'))) {
                 //$this->error->add('ERROR_UPLOAD', $this->language->getMsg('YOU_CAN_UPLOAD_WITH_FILE_EXTENSION_JPG_JPEG_PJPEG'));
                 return false;
             }
             $handle->file_new_name_body = $_filename;
             $handle->process($_filepath);
             if ($handle->processed) {
                 require Yii::app()->basePath . '/components/byte_converter.class.php';
                 $byte = new byte_converter();
                 $byte->set_limit("mb");
                 $img_arr['id'] = 0;
                 $img_arr['image_title'] = $_filename;
                 $img_arr['image_ext'] = $handle->file_src_name_ext;
                 $img_arr['image_path'] = $file_info['physical_path'];
                 $img_arr['image_mime_type'] = $handle->image_src_type;
                 $img_arr['image_width'] = $handle->image_src_x;
                 $img_arr['image_height'] = $handle->image_src_y;
                 $img_arr['image_size'] = $handle->file_src_size;
                 $modelImage = new AImages();
                 $modelImage->image_title = $img_arr['image_title'];
                 $modelImage->image_ext = $img_arr['image_ext'];
                 $modelImage->image_path = $img_arr['image_path'];
                 $modelImage->image_mime_type = $img_arr['image_mime_type'];
                 $modelImage->image_width = $img_arr['image_width'];
                 $modelImage->image_height = $img_arr['image_height'];
                 $modelImage->image_size = $img_arr['image_size'];
                 if ($modelImage->save()) {
                     $img_arr['id'] = $modelImage->id;
                 }
             }
             //upload width thumbnail 110
             $handle->file_new_name_body = $_filename . '_' . Yii::app()->params->width110;
             $handle->image_resize = true;
             $handle->image_x = Yii::app()->params->width110;
             $handle->image_ratio_y = true;
             $handle->process($_filepath);
             if ($handle->processed) {
                 $handle->Clean();
             }
             echo json_encode($img_arr);
             exit;
         } else {
             echo json_encode(array('Upload Fail !'));
             exit;
         }
     } else {
         echo json_encode(array('Can not upload file !'));
         exit;
     }
 }
Esempio n. 2
0
function get_byte($raw)
{
    // $raw : '500kb', '1mb'
    require_once 'lib/byte_converter.class.php';
    $file_raw_size = parse_size($raw);
    $size_in_byte = 0;
    try {
        $byte = new byte_converter();
        $byte->set_limit("tb");
        //show types up to tera byte
        $file_size = $byte->auto($file_raw_size[0], $file_raw_size[1]);
        $size_in_byte = $file_size['b'];
    } catch (Exception $e) {
        echo $e;
    }
    return $size_in_byte;
}