laravel干预图像源在部署时不可读

问题描述 投票:0回答:1

图像类干预不可读!谁能帮我,当我将新照片上传到laravel项目时,为什么在部署时会显示图像无法读取的错误,在开发环境中完全可以,但是在生产中会出现此错误enter image description here

并且这是我在控制器中的干预代码

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

        }
    }
laravel image filenotfoundexception intervention
1个回答
0
投票

[每当我看到此类问题时,每个人都会回答您应该将其存储在项目的公用文件夹中。表示使用此存储空间:链接,但并非总是这样,请记住,如果将文件夹上载到两个不同的项目中,一个public_html和另一个上载到名为例如我的项目的文件夹中,则事物将存储在我的项目中并且laravel将在不存在它们的public_html中搜索它们,一种解决方案是通过以这种方式更改.httacces将整个项目放入公共html中]

<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>
© www.soinside.com 2019 - 2024. All rights reserved.