Mrs_Beginner's avatar

temporary image dos not exist

i have problem with uploading image of my product, i use below code for upload image

 //upload image

        $year = Carbon::now()->year;
        $month = Carbon::now()->month;
        $day = Carbon::now()->day;
        $imagePath = "/upload/images/{$year}/{$month}/{$day}";
        $originalname=$file->getClientOriginalName();
        $filename = md5($originalname. time()).$originalname;
        //check if file exists before
        if($filesystem->exists(public_path("{$imagePath}/{$filename}"))) {
            $filename = Carbon::now()->timestamp . "-{$filename}";
        }
        $file->move(public_path($imagePath) , $filename);
        $imagefinalpath=$imagePath.'/'.$filename;
        //finish uploading

i need $imagefinalpath to store it in my database.

when i use this code for upload image with Postman every thing is ok but when i am using web form an error happening like below The file AppData\Local\Temp\php1AD1.tmp does not exist laravel

my web form code is like below:

 <form role="form" action="{{ route('products.store') }}" method="post" enctype="multipart/form-data">
                    {{ csrf_field() }}
                            <input type="file" name="image" class="form-control" >

</form>

i do not know whats going on here!!!!

i did what someone said in below link but didnt worked for me!

https://github.com/laravel/framework/issues/12350#issuecomment-403194466

0 likes
3 replies
realrandyallen's avatar

This could be a permission issue on that folder or if the file is larger than the settings in your php.ini allows the tmp file won’t be created (default is 2MB)

1 like
Mrs_Beginner's avatar

@REALRANDYALLEN -

file is storing in that folder. but when i use $imagefinalpath = request('image')->store('images'); every thing works for image sent by web form.

it is normal?

realrandyallen's avatar

@MRS_BEGINNER - I'm not sure I understand your question - but that store method does return the path to the file so that's a piece of what you need for your database field.

In your code the only thing I see wrong is your $filename doesn't have the extension on the end of it, which you can grab with $file->getClientOriginalExtension()

2 likes

Please or to participate in this conversation.