Persianguy223's avatar

Image not retrieved

Hello guys,

Currently, I am trying to make sure that uploaded images are retrieved from the DB. However, this does not work. No images are retrieved or shown. I also do not get any error messages.

However, I do believe I think what is causing the problem. The image is stored in a temporary path (/storage//tmp/phpwDLF0O). Which should not happen. Somehow, the temporary path is saved in the DB instead of the filename.

I checked my store method in my controller to see what is causing the problem. I tried to change it from:

if ($request->hasFile('image')) {
            $image = $request->file('image'); //request the file
            $fileName = md5($image->getClientOriginalName() . microtime()) . '.' . $image->getClientOriginalExtension(); //use md5 for security reasons and get the extension.
            $image->storeAs('', $fileName, 'public'); //store the file in the public folder disk.

            $assortment->image_path = $fileName;
            $assortment->save();
        } 

To:

if ($request->hasFile('image')) {
            $image = $request->file('image'); //request the file
            $fileName = md5($image->getClientOriginalName() . microtime()) . '.' . $image->getClientOriginalExtension(); //use md5 for security reasons and get the extension.
        
            $assortment->image_path = $image->storeAs('', $fileName, 'public'); //store the file in the public folder disk.
            $assortment->save();
        } 

Also, I checked the nginx config file to delete the following lines of code:

        location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
               expires 365d;
        }

But I never found them. I am also sure the image is uploaded. Since I wrote a test that checks if a file is uploaded, and that test works. Does anyone know how to solve this problem? I am stuck on this.

0 likes
1 reply

Please or to participate in this conversation.