簡體   English   中英

從不同位置導入excel文件並將其保存到php中的mysql

[英]importing excel file from different location and save it to mysql in php

我是php新手。 我試圖將excel文件導入mysql,它運行良好。 但我只從wamp / www / samp.xls導入excel文件。 我需要從D:或E:等不同位置導入excel文件。 如何獲得該解決方案,請給我一個解決方案。 我的位置代碼是wamp / www / samp.xls:

<html>
  <head>
  <title>Save Excel file details to the database</title>
  </head>
  <body>`enter code here`
    <?php
        include 'db_connection.php';
        include 'reader.php';
        $excel = new Spreadsheet_Excel_Reader();
    ?>
        <table border="1">
        <?php
            $excel->read('samp.xls');
            $x=2;
            while($x<=$excel->sheets[0]['numRows']) {
                $id = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][1] : '';
                $name = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][2] : '';
               $age = isset($excel->sheets[0]['cells'][$x][1]) ? $excel->sheets[0]['cells'][$x][3] : '';
                $email = isset($excel->sheets[0]['cells'][$x][2]) ? $excel->sheets[0]['cells'][$x][4] : '';
                // Save details
                $sql_insert="INSERT INTO students (sid,name,age,email) VALUES ('$id','$name','$age','$email')";
                $result_insert = mysql_query($sql_insert) or die(mysql_error());
              $x++;
            }
        ?>
    </table>
  </body>
</html>

使用基本形式

<form enctype='multipart/form-data'><input type="file" name="excel" /> <input type="submit" value="upload" /></form>

並在php端處理如下形式

$excel->read($_FILES['excel']['tmp_name']);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM