How can i do xlsx file upload from web page to server ? I have issue about read Excel file. I have a php code but i need upload file from web page to my server . Because if i dont upload it, I cannot read file.
this is my php code. In this code i need upload the File.
header('Content-Type: text/plain');
if (isset($argv[1]))
{
$Filepath = $argv[1];
}
elseif (isset($_POST['File']))
{
$Filepath = $_POST['File'];
}
else
{
if (php_sapi_name() == 'cli')
{
echo 'Please specify filename as the first argument'.PHP_EOL;
}
else
{
echo 'Please specify filename as a HTTP GET parameter "File", e.g., "/test.php?File=test.xlsx"';
}
exit;
}
// Excel reader from http://code.google.com/p/php-excel-reader/
require('php-excel-reader/excel_reader2.php');
require('SpreadsheetReader.php');
date_default_timezone_set('UTC');
$StartMem = memory_get_usage();
try
{
$Spreadsheet = new SpreadsheetReader($Filepath);
$BaseMem = memory_get_usage();
$Sheets = $Spreadsheet -> Sheets();
//print_r($Sheets);
$TabloArray=array();
$Satir=array();
foreach ($Sheets as $Index => $Name)
{
$Time = microtime(true);
$Spreadsheet -> ChangeSheet($Index);
foreach ($Spreadsheet as $Key => $Row)
{
//echo $Key.': ';
if($Key==0)
{
continue;
}
if ($Row)
{
$Satir['Isim']=$Row[0];
$Satir['SoyIsim']=$Row[1];
$Satir['Yas']=$Row[2];
$TabloArray[]=$Satir;
}
else
{
var_dump($Row);
}
$CurrentMem = memory_get_usage();
}
}
print_r(json_encode($TabloArray));
}
catch (Exception $E)
{
echo $E -> getMessage();
}
And JavaScript code for read
json_obj = $.parseJSON(veri);//parse JSON
for(var i in json_obj)
{
Isimler[i]=json_obj.Isim;
SoyIsim[i]=json_obj.SoyIsim;
Yas[i]=json_obj.Yas;
var Table=document.getElementById("tablo_icin2");
var td = document.createElement("td");
var tr=document.createElement("tr");
td.appendChild(document.createTextNode(json_obj[i].Isim));
tr.setAttribute("id","element"+i);
tr.appendChild(td);
td = document.createElement("td");
td.appendChild(document.createTextNode(json_obj[i].SoyIsim));
tr.appendChild(td);
td = document.createElement("td");
td.appendChild(document.createTextNode(json_obj[i].Yas));
tr.appendChild(td);
Table.appendChild(tr);
}
Use parser: If you want read file by JavaScript you can use https://github.com/SheetJS/js-xlsx for it. It you want read file by php you can use https://github.com/PHPOffice/PHPExcel/tree/develop/Documentation after upload you file as simple file.