关于实现接收base64图片数据并以图片保存到本地的处理

来源:互联网 发布:30个网络流行词汇 编辑:程序博客网 时间:2024/06/02 21:18
    public function saveBase64File($img,$name=''){        $base_img = str_replace('data:image/jpeg;base64,','', $img);        //  设置文件路径和文件前缀名称        $path = "./Public/uploads/";        $prefix='img';        if($name ==''){            $output_file = $prefix.time().rand(100,999).'.jpg';        }else{            $output_file = $name;        }        $path = $path.$output_file;        //  创建将数据流文件写入我们创建的文件内容中        $ifp = fopen( $path, "wb" );        fwrite( $ifp, base64_decode( $base_img) );        fclose( $ifp );        // 第二种方式        // file_put_contents($path, base64_decode($base_img));        // 输出文件        // print_r($output_file);                $path="/Public/uploads/".$output_file;        return $path;    }

阅读全文
0 0
原创粉丝点击