【问题标题】:The "C:\xampp\tmp\php6A75.tmp" file does not exist or is not readable“C:\xampp\tmp\php6A75.tmp”文件不存在或不可读
【发布时间】:2020-02-26 20:52:59
【问题描述】:

我想在 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>

请帮帮我。

【问题讨论】:

    标签: laravel file-upload laravel-6.2


    【解决方案1】:

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

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

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

    【讨论】:

    • 没有。我没有使用 Storage 类。照片存储在公用文件夹中。但它没有存储在数据库中。
    猜你喜欢
    • 2020-03-18
    • 2020-02-16
    • 2017-01-16
    • 1970-01-01
    • 2013-10-19
    • 2020-01-20
    • 2021-05-08
    • 1970-01-01
    • 2012-03-05
    相关资源
    最近更新 更多