-1

Image class intervention not readable! can anyone help me that why image not readable error show on deployment when i upload new photos to laravel project, which is totally fine in development environment but in production has this error enter image description here

AND this my intervention code in controller

    if($request->hasFile('file')){
        $nameWithExtension =  $request->file('file')->getClientOriginalName();
        $extension =  $request->file('file')->getClientOriginalExtension();
        $fileName = pathinfo($nameWithExtension, PATHINFO_FILENAME);
        $newFileName = $fileName.'_'.time().'.'.$extension;


        $upperExt = strtoupper($extension);
        if($upperExt == 'JPEG' OR $upperExt == 'PNG' OR $upperExt == 'JPG' OR $upperExt == 'GIF'){
            $request->file('file')->storeAs('public/doctor/',$newFileName);
            $request->file('file')->storeAs('public/doctor_small/',$newFileName);
            $request->file('file')->storeAs('public/doctor_small2/',$newFileName);

        //Resize image here 

            $thumbnailpath = public_path('storage/doctor_small/'.$newFileName);
            $img = Image::make($thumbnailpath)->resize(520, 668, function($constraint) {
                $constraint->aspectRatio();
            });
            $img->save($thumbnailpath);

            $thumbnailpath2 = public_path('storage/doctor_small2/'.$newFileName);
            $img2 = Image::make($thumbnailpath2)->resize(100, 100)->save($thumbnailpath2);

        }
    }

1 Answers1

0

Whenever I see this type of question, everyone answers that you should store it in the public folder of the project. says use this storage: link but it is not always like this, you should bear in mind that if you upload the folder in two different projects one public_html and another in a folder called for example my project things will be stored in the folder my project and laravel will search for them in public_html where they don't exist, a solution would be to put the whole project in public html by changing the .httacces this way

<IfModule mod_rewrite.c>
   <IfModule mod_negotiation.c>
       Options -MultiViews -Indexes
   </IfModule>
   RewriteEngine On
   # Handle Authorization Header
   RewriteCond %{HTTP:Authorization} .
   RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
   # Redirect Trailing Slashes If Not A Folder...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_URI} (.+)/$
   RewriteRule ^ %1 [L,R=301]
   # Handle Front Controller...
   RewriteRule ^(.*)$ public/$1 [L]
   RewriteRule ^ index.php [L]
</IfModule>
SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41