exit("0"); } } $files = time(); //传到COS $base64_body = substr(strstr($base64_image_content, ','), 1); //生成本地文件 $new_file = "./tmp/" . $files . ".png"; $data = base64_decode($base64_body); file_put_contents($new_file, $data); $cosfolder = Cosapi::statFolder($bucketName, $faceFolder); if ($cosfolder["code"] != "0") { Cosapi::createFolder($bucketName, $faceFolder); } //要传入腾讯云文件 $dstPath = $faceFolder . $files . ".png"; //查询文件是否存在 $result = Cosapi::stat($bucketName, $dstPath); if ($result["code"] == "0") { Cosapi::del($bucketName, $dstPath); $types = Cosapi::upload($new_file, $bucketName, $dstPath); } else { $types = Cosapi::upload($new_file, $bucketName, $dstPath); } /*清空本地的存储文件及目录 unlink($save_path); */ $file_url = $types["data"]["access_url"]; session_start(); $_SESSION['face'] = $file_url; echo "1";
/** * 删除远程服务器上的单个文件 */ function delete_remote_file($file) { //获取WP配置信息 $cos_options = get_option('cos_options', TRUE); $cos_bucket = esc_attr($cos_options['bucket']); //得到远程路径 $file = str_replace("\\", '/', $file); $del_file_path = str_replace(get_home_path(), '/', $file); try { //实例化存储对象 $qcloud_cos = new Cosapi(); //删除文件 $qcloud_cos->del($cos_bucket, $del_file_path); } catch (Exception $ex) { } return $file; }