tp5 it will save php base64 saved as a picture

 1 public function uploads(){
 2         $logo_data = $this->request->post('logo_base64','');
 3         //$logo_data = $_POST['logo_base64'];
 4         
 5         if(!empty($logo_data)){
 6             //$data = file_get_contents('./1.txt');
 7             $reg = '/data:image\/(\w+?);base64,(.+)$/si';
 8             preg_match($reg,$logo_data,$match_result);
 9 
10             $file_name = time. '.'. () $ Match_result [. 1 ];
 . 11              
12 is              $ logo_path . = WEB_PATH '/ uploads / logo /'. $ File_name ;
 13 is              $ NUM = file_put_contents ( $ logo_path , base64_decode ( $ match_result [2 ]));
 14              
15              
16              IF (! empty ( $ NUM )) {
 . 17                  // after successfully uploaded, then the zoom operation
 18 is                  // Image $ = \ Think \ Image :: Open ($ logo_path);
 . 19                  
20 is                  // accordance with the original image the proportion generate a maximum of 150 * 150 thumbnail image and save it as thumb.png
 21                 //$image->thumb(102, 36)->save($logo_path);
22                 
23                 $result = ['code'=>200,'msg'=>'ok'];
24             }else{
25                 $result = ['code'=>100,'msg'=>'no'];
26             }
27         }else{
28             $result = ['code'=>100,'msg'=>'参数错误'];
29         }
30         return ajax($result);
31     }

 

Guess you like

Origin www.cnblogs.com/liwuming/p/11130156.html