Laravel - File Upload button not working in live server

1.5k views Asked by At

In the laravel project the file upload button was working fine during local development using WAMP Server. But when I uploaded the project to my shared hosting server, the file upload button does not work anymore. The button is disabled.

In my localhost the upload button works, but in my live server the file upload button does not work(disabled)

Pls help I don't know what to do.

in my controller, here is the code for upload

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 '{}';
    }
}

in my view, here is the code that handles the upload

                    <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

There are 1 answers

0
Obot Ernest On

In the laravel .env file, the url was not properly set. So I had to correct it and it worked.

Old url - http://example.com

New url - https://example.com/ (working url)