PHP Excel导入到MYSQL数据库在本地主机上运行良好,但在在线服务器上不正常



PHP Excel导入到MYSQL数据库在本地主机上运行良好,但在在线服务器上运行不佳。我想从excel表中导入一个数据库。我用PHP写了一段代码,用户可以选择一个excel文件并导入它。我的代码在本地主机上运行良好,但在服务器上执行同样的操作时遇到了问题。

<?php
include_once("db_connect.php");
require_once('vendor/php-excel-reader/excel_reader2.php');
require_once('vendor/SpreadsheetReader.php');
if (isset($_POST["import"]))
{
$allowedFileType = ['application/vnd.ms-excel','text/xls','text/xlsx','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
if(in_array($_FILES["file"]["type"],$allowedFileType)){
$targetPath = 'uploads/'.$_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);
$Reader = new SpreadsheetReader($targetPath);
$sheetCount = count($Reader->sheets());
for($i=0;$i<$sheetCount;$i++)
{
$Reader->ChangeSheet($i);
foreach ($Reader as $Row)
{
$u_id = "";
if(isset($Row[0])) {
$u_id = mysqli_real_escape_string($conn,$Row[0]);
}
$u_name = "";
if(isset($Row[1])) {
$u_name = mysqli_real_escape_string($conn,$Row[1]);
}
$s_name = "";
if(isset($Row[2])) {
$s_name = mysqli_real_escape_string($conn,$Row[2]);
}

if (!empty($u_id) || !empty($u_name) || !empty($s_name)) {
$query = "insert into school_list(user_id,user_name,school_name) values('".$u_id."','".$u_name."','".$s_name."')";
$result = mysqli_query($conn, $query);
if (! empty($result)) {
$type = "success";
$message = "Excel Data Imported into the Database";
} else {
$type = "error";
$message = "Problem in Importing Excel Data";
}
}
}
}
}
else
{ 
$type = "error";
$message = "Invalid File Type. Upload Excel File.";
}
}
?>

我有个错误此页面不工作******.com当前无法处理此请求。HTTP错误500

致命错误:未捕获错误:在中找不到类"ZipArchive"/home/rp16cfpfmt/public_html/goodluck_sales/adminarea/excel/vender/SpreadsheetReader_XLSX.php:217堆栈跟踪:#0

您似乎必须安装Zip扩展。

关于zip扩展,请查看官方页面

最新更新