Laravel-文件上传按钮在实时服务器中不起作用

时间:2020-10-22 01:47:30

标签: php laravel laravel-5 laravel-6 laravel-6.2

在laravel项目中,使用WAMP Server进行本地开发期间,文件上传按钮运行正常。但是,当我将项目上载到共享托管服务器时,文件上载按钮不再起作用。该按钮被禁用。

在我的本地主机中,上传按钮起作用,但是在我的实时服务器中,文件上载按钮不起作用(禁用)

请帮助我不知道该怎么办。

在我的控制器中,这是上传代码

public function upload(Request $request){

    $type = array(
        "jpg"=>"image",
        "jpeg"=>"image",
        "png"=>"image",
        "svg"=>"image",
        "webp"=>"image",
        "gif"=>"image",
        "mp4"=>"video",
        "mpg"=>"video",
        "mpeg"=>"video",
        "webm"=>"video",
        "ogg"=>"video",
        "avi"=>"video",
        "mov"=>"video",
        "flv"=>"video",
        "swf"=>"video",
        "mkv"=>"video",
        "wmv"=>"video",
        "wma"=>"audio",
        "aac"=>"audio",
        "wav"=>"audio",
        "mp3"=>"audio",
        "zip"=>"archive",
        "rar"=>"archive",
        "7z"=>"archive",
        "doc"=>"document",
        "txt"=>"document",
        "docx"=>"document",
        "pdf"=>"document",
        "csv"=>"document",
        "xml"=>"document",
        "ods"=>"document",
        "xlr"=>"document",
        "xls"=>"document",
        "xlsx"=>"document"
    );

    if($request->hasFile('aiz_file')){
        $upload = new Upload;
        $upload->file_original_name = null;

        $arr = explode('.', $request->file('aiz_file')->getClientOriginalName());

        for($i=0; $i < count($arr)-1; $i++){
            if($i == 0){
                $upload->file_original_name .= $arr[$i];
            }
            else{
                $upload->file_original_name .= ".".$arr[$i];
            }
        }

        $upload->file_name = $request->file('aiz_file')->store('uploads/all');
        $upload->user_id = Auth::user()->id;
        $upload->extension = $request->file('aiz_file')->getClientOriginalExtension();
        if(isset($type[$upload->extension])){
            $upload->type = $type[$upload->extension];
        }
        else{
            $upload->type = "others";
        }
        $upload->file_size = $request->file('aiz_file')->getSize();
        $upload->save();

        return '{}';
    }
}

在我看来,这是处理上传的代码

                    <div class="form-group">
                        <label for="types">{{translate('System Logo - White')}}</label>
                        <div class="input-group" data-toggle="aizuploader" data-type="image">
                            <div class="input-group-prepend">
                                <div class="input-group-text bg-soft-secondary">{{ translate('Browse') }}</div>
                            </div>
                            <div class="form-control file-amount">{{ translate('Choose Files') }}</div>
                            <input type="hidden" name="system_logo_white" value="{{ get_setting('system_logo_white') }}" class="selected-files">
                        </div>

1 个答案:

答案 0 :(得分:1)

在laravel .env文件中,URL设置不正确。所以我不得不纠正它,它才起作用。

旧网址-http://example.com

新网址-https://example.com/(有效网址)