master
cody 6 months ago
parent 32cbc7834e
commit 19e7af0018

@ -25,6 +25,7 @@ use App\Models\ProductParamedicLevel;
use App\Models\Project; use App\Models\Project;
use App\Models\Recharge; use App\Models\Recharge;
use App\Models\Refund; use App\Models\Refund;
use App\Models\Uploads;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
@ -1960,29 +1961,33 @@ class OrdersController extends CommonController
'format' => 'png', 'format' => 'png',
// 允许访问本地文件解决Blocked access to file警告 // 允许访问本地文件解决Blocked access to file警告
'enable-local-file-access' => true, 'enable-local-file-access' => true,
// 禁止加载图片(如果不需要图片可以开启)
// 'no-images' => true,
// 禁止加载JavaScript如果不需要JS可以开启
// 'no-js' => true,
]; ];
$tempPath = storage_path('app/temp/' . uniqid() . '.' . $options['format']); // 目录
$save_folder = "public";
// 文件名
$name = "协议" . date("YmdHis") . uniqid(). "." . $options['format'];
$tempPath = storage_path("app/{$save_folder}/" . $name. '.' . $options['format']);
// 确保临时目录存在 // 确保临时目录存在
Storage::makeDirectory('temp'); Storage::makeDirectory($save_folder);
// 2. 生成图片到临时文件需要两个参数html内容和输出路径 // 2. 生成图片到临时文件需要两个参数html内容和输出路径
SnappyImage::setOptions($options)->generateFromHtml($html, $tempPath); SnappyImage::setOptions($options)->generateFromHtml($html, $tempPath);
// 3. 读取临时文件内容并转换为Base64
$imageContent = file_get_contents($tempPath);
$base64Image = 'data:image/' . $options['format'] . ';base64,' . base64_encode($imageContent);
// 4. 删除临时文件(清理资源) $upload = new Uploads();
unlink($tempPath); $upload->original_name = $name;
return response()->json([ $upload->folder = "agreement";
"errorcode" => "200", $upload->name = $name;;
"errormsg" => "success", $upload->extension = $options['format'];
"data" => [ $upload->creator_type = get_class($this->manager);
"base64_image" => $base64Image $upload->creator_id = $this->manager->id;
] $upload->size = Storage::size($save_folder . "/" . $name);
]); $upload->save();
if ($save_folder == "public") {
$upload->public_path = "/storage/" . $name;
} else {
$upload->public_path = null;
}
return response()->json($upload);
} }
} }

Loading…
Cancel
Save