安装后我
SELECT IN
我要上传图片,并提交表单后,出现此错误。
文件“ C:\ xampp \ tmp \ php1D5F.tmp”不存在
composer require intervention/image
我尝试更改代码:
public function store(ArticleRequest $request)
{
auth()->loginUsingId(1);
$imagesUrl = $this->uploadImages($request->file('images'));
$article = auth()->user()->article()->create(array_merge($request->all(), ['images' => $imagesUrl]));
$article->categories()->attach(request('category'));
return redirect(route('articles.index'));
}
protected function uploadImages($file)
{
$year = Carbon::now()->year;
$imagePath = "/upload/images/{$year}/";
$filename = $file->getClientOriginalName();
$file = $file->move(public_path($imagePath) , $filename);
$sizes = ["300" , "600" , "900"];
$url['images'] = $this->resize($file->getRealPath() , $sizes , $imagePath , $filename);
$url['thumb'] = $url['images'][$sizes[0]];
return $url;
}
private function resize($path , $sizes , $imagePath , $filename)
{
$images['original'] = $imagePath . $filename;
foreach ($sizes as $size) {
$images[$size] = $imagePath . "{$size}_" . $filename;
Image::make($path)->resize($size, null, function ($constraint) {
$constraint->aspectRatio();
})->save(public_path($images[$size]));
}
return $images;
}
它很好地返回了$ imagesUrl。
$imagesUrl = $this->uploadImages($request->file('images'));
return $imagesUrl;
我认为来自images
300 "/upload/images/2018/300_tvto.jpg"
600 "/upload/images/2018/600_tvto.jpg"
900 "/upload/images/2018/900_tvto.jpg"
original "/upload/images/2018/tvto.jpg"
thumb "/upload/images/2018/300_tvto.jpg"
那是什么解决方案?
答案 0 :(得分:0)
您需要将ArticleRequest转换为Request,并将其带到如下所示的控制器页面。
public function store(Request $request)
{
$this->validate(request(),[
'title' => 'required|max:250',
'type' => 'required',
'description' => 'required',
'image' => 'required|mimes:jpeg,png,bmp',
'path.*' => 'required|mimes:avi,mp4,.mov,wmv',
'price' => 'required',
]);