我通过 Ajax 将 png 图像文件发送到 base64 中的控制器。我已经测试并确保控制器已收到 id 但仍无法将其保存到公用文件夹。
这是我的控制器
public function postTest() {
$data = Input::all();
//get the base-64 from data
$base64_str = substr($data->base64_image, strpos($data->base64_image, ",")+1);
//decode base64 string
$image = base64_decode($base64_str);
$png_url = "product-".time().".png";
$path = public_path('img/designs/' . $png_url);
Image::make($image->getRealPath())->save($path);
// I've tried using
// $result = file_put_contents($path, $image);
// too but still not working
$response = array(
'status' => 'success',
);
return Response::json( $response );
}
原文由 Expl0de 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 public 文件夹 image 中存储或保存 base64 图像并返回文件路径。