为了进行开发,我在我的 Laravel 项目中在 Windows 上工作。我试图让文件上传在本地工作。
我的上传代码:
public function addPicture(Request $request, $id)
{
$bathroom = Bathroom::withTrashed()->findOrFail($id);
$validatedData = Validator::make($request->all(), [
'afbeelding' => 'required|image|dimensions:min_width=400,min_height=400',
]);
if($validatedData->fails())
{
return Response()->json([
"success" => false,
"errors" => $validatedData->errors()
]);
}
if ($file = $request->file('afbeelding')) {
$img = Image::make($file);
$img->resize(3000, 3000, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$img->stream();
$uid = Str::uuid();
$fileName = Str::slug($bathroom->name . $uid).'.jpg';
$this->createImage($img, 3000, "high", $bathroom->id, $fileName);
$this->createImage($img, 1000, "med", $bathroom->id, $fileName);
$this->createImage($img, 700, "thumb", $bathroom->id, $fileName);
$this->createImage($img, 400, "small", $bathroom->id, $fileName);
$picture = new Picture();
$picture->url = '-';
$picture->priority = '99';
$picture->alt = Str::limit($bathroom->description,100);
$picture->margin = 0;
$picture->path = $fileName;
$picture->bathroom_id = $id;
$picture->save();
return Response()->json([
"success" => true,
"image" => asset('/storage/img/bathroom/'.$id.'/small/'.$fileName),
"id" => $picture->id
]);
}
我确实运行了: php artisan storage:link
并且可以使用以下路径D:\Documents\repos\projectname\storage\app。当我上传文件时,我得到:
Storage::put( $this->getUploadPath($bathroomId, $fileName, $quality), $img->stream('jpg',100));
创建图像函数。我怎样才能让它在 Windows 上运行,以便我可以在本地测试我的网站?
慕桂英546537
慕妹3146593
精慕HU