I want to import/upload excel files to sql server via cake php, it will occur Undefined variable: ext and Undefined index: the code are shown as below. Is there any mistake in my code? Thanks in advance!


App::import('Vendor', 'php-excel-reader/excel_reader2'); 
class UploadsController extends RealTimeAnalysisAppController

public function upload()

$destination = realpath('../../app/webroot/uploads/excel/' . '/'); 

$ext = substr($_FILES['Upload']['XLS_File'], strrpos($_FILES['Upload']['XLS_File'], '.') + 1);
$path = $destination.'excel'.$ext;
move_uploaded_file($_FILES['Upload']['tmp_name'], $path);

$data = new Spreadsheet_Excel_Reader($path, true);

$temp = $data->dumptoarray();

foreach ($temp as $key=>$val)



Lets just start off with line 11, did you mean to not put an opening bracket on your if statement ?