"C:\xampp\tmp\php6A75.tmp" 文件不存在或不可读

The "C:\xampp\tmp\php6A75.tmp" file does not exist or is not readable

我想在larvel-6.2上传图片,但是显示 "C:\xampp\tmp\php99C0.tmp" 文件不存在或不可读。我的管理控制器:

class AdminController extends Controller
{
    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'];
        // resize the image to a width of 300 and constrain aspect ratio (auto height)
        $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;
    }

}

我的 CourseController 存储函数代码:

 public function store(CourseRequest $request)
    {


        $imageUrl = $this->uploadImages($request->file('images'));

        auth()->user()->course()->create(array_merge($request->all() , ['images' => $imageUrl]));


        return redirect(route('courses.index'));
    }

我的表单查看代码:我的表单查看代码: 我的表单查看代码:我的表单查看代码: 我的表单查看代码:我的表单查看代码:


 <form action="{{route('courses.store')}}" method="post" enctype="multipart/form-data">
                        {{csrf_field()}}
                        @include('Admin.section.errors')
                        <div class="form-group">
                            <label for="title" class="bmd-label-floating text-white">Course Title</label>
                            <input type="text" class="form-control" name="title" id="title" placeholder="Enter Course title" value="{{old('title')}}">
                        </div>

                        <div class="form-group col-md-4">
                            <label for="Type">Course Type</label>
                            <select id="Type" name="type" class="form-control">
                                <option value="vip" class="text-dark">VIP</option>
                                <option value="cash" class="text-dark">Cash</option>
                                <option value="free" class="text-dark" selected>free</option>
                            </select>
                        </div>

                        <div class="form-group mt-3">
                            <label for="body" class="bmd-label-floating text-white">Course Body</label>
                            <textarea rows="15" class="form-control" name="body" id="body" placeholder="Enter Course body">{{old('body')}}</textarea>
                        </div>

                            <div class="form-file-upload mt-4">
                                <label for="pictures" class=" text-white">Course Pictures</label>
                                <input type="file" name="images" class="form-file-upload" id="pictures"  placeholder="Enter pictures" value="{{old('images')}}">
                            </div>

                        <div class="form-group mt-5">
                            <label for="tags" class=" text-white">Course Price</label>
                            <input type="text" name="price" class="form-control" id="tags"  placeholder="Enter Price" value="{{old('price')}}">
                        </div>
                            <div class="form-group mt-1">
                                <label for="tags" class=" text-white">Course Tags</label>
                                <input type="text" name="tags" class="form-control" id="tags"  placeholder="Enter Tags" value="{{old('tags')}}">
                            </div>



                        <button type="submit" class="btn btn-primary">Submit</button>
                    </form>

请帮助我。

如果您使用存储class,您可以将图像移动到存储文件夹中的正确路径。

Storage::disk('local')->put('/uploads/images/' . $year .'/', $filename);

您需要 运行 命令 PHP Artisan storage:link 在存储文件夹和您的 public 文件夹之间创建符号链接。