gpt4 book ai didi

javascript - 将图像(来自 javascript)保存在公共(public)文件夹中(通过 php)

转载 作者:行者123 更新时间:2023-12-02 23:31:27 25 4
gpt4 key购买 nike

我正在尝试使用这个包 https://vuejsexamples.com/a-beautiful-vue-component-for-image-cropping-and-uploading/但后来我想知道如何将图像保存在文件夹中。

我正在尝试在 php 中执行此操作,以便之后可以轻松使用该路由,但如果更简单的话,也可以使用 JS。

public function uploadfile(Request $request){
$img = $request->img;
$newlocation = $request->newlocation;
$filename = $request->filename;

$img = str_replace('data:image/png;base64,', '', $request->img); //I tried with and without this

return file_put_contents ($newlocation . "/" . $filename , $img );
}

我实际上在我的公共(public)文件夹中得到了一张图像,但内容绝对不是我想要的:)image.jpg 包含文本 C:\Users\usr\AppData\Local\Temp\phpEE72.tmp

最佳答案

我发现此链接在上传图像时非常有用: https://hdtuto.com/article/laravel-57-image-upload-with-validation-example

在我的 Controller 中,验证后我有类似的东西,它允许不同的图像文件类型,例如 png 和 jpg:

$name = $request->input('name');
$getimageName = $name.'.'.$request->image->getClientOriginalExtension();
$request->image->move(public_path('filelocation'), $getimageName);

在我的 filesystems.php 文件中:

'disks' = > [
'filelocation' => [
'driver' => 'local',
'root' => public_path().'/foldername',
'url' => env('APP_URL').'/public/foldername',
'visibility' => 'public',
]
]

关于javascript - 将图像(来自 javascript)保存在公共(public)文件夹中(通过 php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56481664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com