我有這個 PHP 程式碼,用於使用 xampp 中的 PhpSpreadsheet 將 excel 匯入 mysql。這段程式碼在 Windows 環境中運行時沒問題,但如果我使用 XAMPP Linux 將其託管到 Linux 伺服器(Ubuntu 22.04),則會出現錯誤「HTTP ERROR 500」。我已經根據 phpspreadsheet.readthedocs.io 文件安裝了 PhpSpreadsheet 所需的所有軟體包和擴充功能。如果這個錯誤是伺服器端的,我該怎麼辦?請幫忙
這些是我的導入文件的程式碼
作曲家.json
{
"name": "mark/import1",
"autoload": {
"psr-4": {
"Mark\\Import1\\": "src/"
}
},
"authors": [
{
"name": "mark"
}
],
"require": {
"phpoffice/phpspreadsheet": "^1.28"
},
"config": {
"platform": {
"php": "8.1"
}
}
}
導入程式碼
<?php
$con = mysqli_connect('localhost','root','','db_import');
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
if(isset($_POST['save_excel_data']))
{
$fileName = $_FILES['import_file']['name'];
$file_ext = pathinfo($fileName, PATHINFO_EXTENSION);
$allowed_ext = ['xls','csv','xlsx'];
if(in_array($file_ext, $allowed_ext))
{
$inputFileNamePath = $_FILES['import_file']['tmp_name'];
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileNamePath);
$data = $spreadsheet->getActiveSheet()->toArray();
foreach($data as $row)
{
$fullname = $row['0'];
$email = $row['1'];
$phone = $row['2'];
$course = $row['3'];
$studentQuery = "INSERT INTO students (fullname,email,phone,course)
VALUES('$fullname','$email','$phone','$course')";
$result = mysqli_query($con, $studentQuery);
$msg = true;
}
}
}