0

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);
}

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I dont need NodeJs i need JavaScript so i am using this code in my page not server
1

Why not just upload the file to the server and save its path to the database. And then when you want to read it, fetch the path from database relative to the upload folder of the excel file.

6 Comments

How can i do upload excel file to the server ?
Take a look at this link
there is nothing about upload excel file from web page to server
Are you sure? the upload script is included in his post.
Get the filename and the path where to save the excel file and then save filename + filepath to your database.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.