Php 导入excel文件时出错
Php 导入excel文件时出错,php,Php,我有一个excel文件,其中包含我的学生表的数据。 现在我正在尝试将此文件导入mysql中的学生表中。 这是我将数据从excel导入学生表的代码。 <?php require_once("class/connection.php"); include("libs/Excel/reader.php"); //change-- table name,title and imgdir $table_name = "student"; $title="
我有一个excel文件,其中包含我的学生表的数据。
现在我正在尝试将此文件导入mysql中的学生表中。
这是我将数据从excel导入学生表的代码。
<?php
require_once("class/connection.php");
include("libs/Excel/reader.php");
//change-- table name,title and imgdir
$table_name = "student";
$title="Excel Import";
$page = $_SERVER['PHP_SELF'];
if($_REQUEST["Save"])
{
// ExcelFile($filename, $encoding);
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('CP1251');
//assign filename
$data->read($_FILES['file']['tmp_name']);
for ($x = 2; $x <= count($data->sheets[0]["cells"]); $x++)
{
$studname = $data->sheets[0]["cells"][$x][1];
$phno = $data->sheets[0]["cells"][$x][2];
$mobno = $data->sheets[0]["cells"][$x][3];
$email = $data->sheets[0]["cells"][$x][4];
$clgname = $data->sheets[0]["cells"][$x][5];
$streamname = $data->sheets[0]["cells"][$x][6];
$remarks = $data->sheets[0]["cells"][$x][7];
$gender = $data->sheets[0]["cells"][$x][8];
$address = $data->sheets[0]["cells"][$x][9];
$query = "INSERT INTO " . $table_name . "(studname,phno,mobno,email,clgname,streamname,remarks,gender,address)
values('$studname','$phno','$mobno','$email','$clgname','$streamname','$remarks','$gender','$address')";
mysql_query($query) or die(mysql_error());
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Panel -<?php echo $title;?></title>
<link rel="SHORTCUT ICON" type="image/x-icon" href="images/cloelle_favicon.ico">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><?php include("header.php");?></td>
</tr>
<tr>
<td align="center" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
</table></td>
<td width="6"><img src="images/home_box_rt.jpg" width="6" height="28" /></td>
</tr>
<tr>
<td background="images/home_box_lbg.jpg"> </td>
<td height="120" align="center" valign="top" class="successmsg">
<?php
if($_REQUEST['submit'])
{
echo "Your data Transfered Successfully!";
}
else
{
echo "Please Upload Your Excel File Here!";
}
?>
<form id="StdForm" name="StdForm" enctype="multipart/form-data" method="post" onsubmit="javascript: return chkValid();">
<p>
<input type="file" name="file" id="file" />
</p>
<p>
<input type="submit" id="Save" name="Save" class="button" value="submit" />
</p>
</form></td>
<td background="images/home_box_rbg.jpg"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><?php include("footer.php"); ?></td>
</tr>
</table>
</body>
</html>
那么我错过了什么呢?提前感谢
请确保您试图读取的文件以microsoft excel(.xls)格式保存。我在尝试使用excel reader读取时也遇到同样的错误,然后发现我的.xls扩展名文件是CSV格式的。所以我打开了我的文件并保存为MicrosoftExcell(.xls),它成功了。
php.ini中可能缺少一些设置。。。?你知道@Smitais allow\u url\u fopen是在php.ini中设置的吗?如果是,那么我认为它与php.ini没有任何关系。您的.xls文件的权限可能有问题。我刚才注意到,您试图读取的文件是.tmp。是否应该是.xls?如果您使用的是Linux服务器,则存在权限问题。这将不允许创建文件。
The filename C:\xampp\tmp\phpFCD3.tmp is not readable