MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/chartapi.imenso.co/app/Http/Controllers/APIController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Chart_data;
use App\Models\Data_record;
use App\Imports\ImportChartData;
use Maatwebsite\Excel\Facades\Excel;
use Validator;

class APIController extends Controller
{
    public function upload(Request $request)
	{
		$file = $request->file('file');
		$mimetype = $file->getMimeType();
		
		$allowedFileType = array('application/vnd.ms-excel', 'text/xls', 'text/xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

    	if(in_array($mimetype, $allowedFileType)) {

    		$truncate_sql = Chart_data::query()->truncate();
                        
	        if (! empty($truncate_sql)) {
		        $excel = Excel::import(new ImportChartData, request()->file('file'));
		        if (isset($excel)) {
		        	$fileName = $file->getClientOriginalName();
		        	$dataRecord = new Data_record;
		        	$dataRecord->file_name = $fileName;
		        	$result = $dataRecord->save();

		        	if ($result)
		        	{
		        		$finalOutput = array("type"=>"success", "message"=>"Data imported successfully");
		        	} else {
		        		$finalOutput = array("type"=>"error", "message"=>"Problem in insertion of file details");
		        	}
		        } else {
		        	$finalOutput = array("type"=>"error", "message"=>"Problem in Importing Excel Data");
		        }
	    	} else {
	    		$finalOutput = array("type"=>"error", "message"=>"Problem in Deletion of Old Excel Data.");
	    	}
    	} else {
    		$finalOutput = array("type"=>"error", "message"=>"Invalid File Type. Upload Excel File.");
		}

		return json_encode($finalOutput);    
	}
}