示例#1
0
 public static function generate_file_name($type = 'file')
 {
     $file_info = array();
     $curr_info = date("Y,m,d,H,i,s");
     list($year, $month, $day, $hour, $minute, $second) = @split(",", $curr_info);
     $filename = $year . $month . $day . $hour . $minute . $second . AFunction::random_generator(5);
     $file_info['name'] = $filename;
     $file_info['host_path'] = "/uploads/" . $type . "/{$year}/{$month}/";
     $file_info['physical_path'] = $type . "/{$year}/{$month}/";
     return $file_info;
 }
示例#2
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;
     }
 }
示例#3
0
 public function clearCacheAssets($where)
 {
     $get_sub_folders = array();
     switch ($where) {
         case 'adm':
             //Clear the assets folder
             $get_sub_folders = AFunction::get_subfolders_name(dirname(dirname(dirname(__FILE__))) . '/adm/' . 'assets');
             foreach ($get_sub_folders as $folder) {
                 AFunction::recursive_remove_directory(dirname(dirname(dirname(__FILE__))) . '/adm/' . 'assets/' . $folder);
             }
             break;
         case 'web':
             $get_sub_folders = AFunction::get_subfolders_name(dirname(dirname(dirname(__FILE__))) . '/web/' . 'assets');
             //var_dump($get_sub_folders);exit();
             foreach ($get_sub_folders as $folder) {
                 AFunction::recursive_remove_directory(dirname(dirname(dirname(__FILE__))) . '/web/' . 'assets/' . $folder);
             }
             break;
         default:
             break;
     }
     return;
 }