laravel干预映像源在部署时不可读 [英] laravel intervention image source not readable on deployment

查看:60
本文介绍了laravel干预映像源在部署时不可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图像类干预不可读! 任何人都可以帮助我,为什么当我将新照片上传到laravel项目时,为什么在部署时会显示图像无法读取的错误, 在开发环境中完全可以,但是在生产中会出现此错误 在此处输入图片描述

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

        }
    }

推荐答案

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

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>

这篇关于laravel干预映像源在部署时不可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆