1. 程式人生 > >data:image/jpeg;base64 資料流處理,儲存至oss

data:image/jpeg;base64 資料流處理,儲存至oss

$img_content = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/2wBDAQMDAwQDBAgEBAgQCwkLEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBD/wAARCAC2ALYDAREAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD8qqACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKAPoz/hj9/8AooQ/8FX/ANur8w/4iQv+gb/yf/7Q/oz/AIl/f/Qw/wDKX/3QP+GP3/6KEP8AwVf/AG6j/iJC/wCgb/yf/wC0D/iX9/8AQw/8pf8A3QP+GP3/AOihD/wVf/bqP+IkL/oG/wDJ/wD7QP8AiX9/9DD/AMpf/dA/4Y/f/ooQ/wDBV/8AbqP+IkL/AKBv/J//ALQP+Jf3/wBDD/yl/wDdA/4Y/f8A6KEP/BV/9uo/4iQv+gb/AM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AoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoAKACgAoA//9k="
; if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result)){ //print_r($result); $ext = $result[2]; $filename = "./test.{$ext}"; //echo base64_decode(str_replace($result[1], '', $img_content)); echo filesize($new_file); if (file_put_contents($filename, base64_decode(str_replace($result
[1], '', $img_content)))){ echo '新檔案儲存成功:', $filename; } }
  //圖片裁剪
   public function imgShear(Request $request){
         if ($request->isMethod('post')) {
             $img_content = $request->input('imgData');
             if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content
, $result)){ $type = $result[2]; $imgData = base64_decode(str_replace($result[1], '', $img_content)); $path = self::BASE_UPLOAD_FOLDER .'/' . Uploader::getCommonPath() .".{$type}"; OSS::uploadContent(Config::get('app.bucketName'), $path, $imgData); $url = Config::get('app.ossUrl') . '/' . $path; //echo $url;die; /*$fileSize = filesize($path); echo $fileSize;die; $url = Uploader::ossCommonUpload(base64_decode(str_replace($result[1], '', $img_content)),$fileSize,$path);*/ if (isset($url)) { return response()->json ( array('code'=>1,'msg'=>'剪下成功','url'=>$url)); }else{ return response()->json ( RspManager::getRspInfo(2,'剪下失敗')); } } }else{ return view($this->baseViewPath . 'imgshear'); } }