我想使用php導入excel數據到mysql。我的程序工作沒有任何錯誤,如果我已經寫了excel文件的路徑爲硬編碼。但是,如果我當時正在嘗試使用上傳功能,則會遇到一個錯誤。我的錯誤如下。 :我想使用php導入excel數據到mysql使用php
文件名C:\ WAMP \ tmp目錄\ php1FC.tmp不可讀
我也提供我的代碼以供參考:
include 'config.php';
require_once 'Excel/reader.php';
$allowedExts = array("xls","xlsx");
$temp = explode(".", $_FILES["file"]["name"]);
if (in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$filename=$_FILES["file"]["name"] ;
$filetype=$_FILES["file"]["type"] ;
$filesize=$_FILES["file"]["size"] ;
$filetemp=$_FILES["file"]["tmp_name"];
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
$handle = fopen($filetemp, "r");
$data = new Spreadsheet_Excel_Reader();
$data->read($filetemp);
$numr=$data->sheets[0]['numRows'];
for ($i = 2; $i <= $numr ; $i++)
{
$gender=$data->sheets[0]['cells'][$i][1];
$txtname=$data->sheets[0]['cells'][$i][2];
$txtusername = $data->sheets[0]['cells'][$i][3];
$txtphone=$data->sheets[0]['cells'][$i][4];
$txtlandno=$data->sheets[0]['cells'][$i][5];
$txtwing=$data->sheets[0]['cells'][$i][6];
$txtemail=$data->sheets[0]['cells'][$i][7];
$txtflat=$data->sheets[0]['cells'][$i][8];
$intercom=$data->sheets[0]['cells'][$i][9];
$userstatus=$data->sheets[0]['cells'][$i][10];
$livestatus=$data->sheets[0]['cells'][$i][11];
$flattype=$data->sheets[0]['cells'][$i][12];
$area1=$data->sheets[0]['cells'][$i][13];
$txtbuilding=$data->sheets[0]['cells'][$i][14];
$housingloan=$data->sheets[0]['cells'][$i][15];
$txtparking=$data->sheets[0]['cells'][$i][16];
$principalopBal=$data->sheets[0]['cells'][$i][17];
$interestBal=$data->sheets[0]['cells'][$i][18];
$servicetax=$data->sheets[0]['cells'][$i][19];
$txtgym=$data->sheets[0]['cells'][$i][20];
$txtcable=$data->sheets[0]['cells'][$i][21];
$txtswim=$data->sheets[0]['cells'][$i][22];
$txtclub=$data->sheets[0]['cells'][$i][23];
$unittype=$data->sheets[0]['cells'][$i][24];
我不明白什麼問題。我想執行這個導入Excel數據功能。我希望用戶可以爲此自行上傳自己的Excel文件。所以請幫助我解決這個問題。
非常感謝。我的問題解決了。 –