如何在Laravel(到目录)中移动base64解码图像


How to move a base64 decoded image in Laravel (to directory)?

我有一个表单,我在其中上传了base64encode的图像。

<input type=hidden value=.....(base64encode string) />

在 Laravel 的方法(我处理输入数据的地方)中,我有

$data = Request::all(); // get all input data
$img = base64_decode($data["img"]); // my decoded image

如何在(任何)目录中移动此解码图像?在拉拉维尔的手册中,我读到了

$request->file('photo')->move($destinationPath);

但我不知道如何在我的情况下使用它。

如果有人还在找,这是我的解决方案我正在寻找一种在本地(在浏览器中)优化图像然后上传它的方法;这就是我在我的 laravel 应用程序中接收它的方式:

Route::post('myroute', function(Illuminate'Http'Request $data){
   $base64_str = substr($data->image, strpos($data->image, ",")+1); // get the image code
   $image = base64_decode($base64_str); // decode the image
   file_put_contents('/path/newImage.JPG',$image); // move the image to the desired path with desired name and extension  
)};
$imageName = rand(11111, 99999) . '_' . time() . '.jpg';
$path = 'uploads/'.$directory_name."/". $imageName;
Storage::disk('local')->put($path, base64_decode($image));

试试这个,你可以从你的配置/文件系统更改/创建磁盘