Ad

The "C:\xampp\tmp\php6A75.tmp" File Does Not Exist Or Is Not Readable

- 1 answer

I want to upload image in larvel-6.2, But show The "C:\xampp\tmp\php99C0.tmp" file does not exist or is not readable. My Admin Controller :

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;
    }

}

and my CourseController store function code:

 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'));
    }

my Form View Code : my Form View Code : my Form View Code : my Form View Code : my Form View Code : my Form View Code :


 <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>

Please Help me.

Ad

Answer

If you use the Storage class, you can move the image into the correct path in the storage folder.

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

You need to run the command PHP Artisan storage:link to create a symlink between the storage folder and your public folder.

Ad
source: stackoverflow.com
Ad