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!

<?php

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

public function upload()
{

$destination = realpath('../../app/webroot/uploads/excel/' . '/'); 
if(isset($_FILES['Upload']['XLS_File']))

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

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

$val['0'];

}
}
}}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.