Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Excel导入MYSQL数据库在本地主机上工作正常,但在在线服务器上工作不正常_Php_Mysql_Excel_Database_Import - Fatal编程技术网

PHP Excel导入MYSQL数据库在本地主机上工作正常,但在在线服务器上工作不正常

PHP Excel导入MYSQL数据库在本地主机上工作正常,但在在线服务器上工作不正常,php,mysql,excel,database,import,Php,Mysql,Excel,Database,Import,PHP Excel导入MYSQL数据库在localhost上运行良好,但在在线服务器上运行不正常。 我想从excel工作表导入数据库。我用PHP编写了一段代码,其中用户选择一个excel文件并导入它。我的代码在localhost上运行良好,但在在线服务器上执行同样的操作时遇到问题 <?php include_once("db_connect.php"); require_once('vendor/php-excel-reader/excel_reader2.php'); require_

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

<?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/rpa16cfpf0mt/public_html/goodluck_sales/adminarea/excel/vendor/SpreadsheetReader_XLSX.php:217 堆栈跟踪:0

看来您必须安装Zip扩展


关于zip扩展名,

是否有错误消息?是,此页面无法工作******。com当前无法处理此请求。HTTP错误500您在本地主机上的服务器上是否安装了相同版本的php?您的代码易受SQL注入攻击。你应该使用事先准备好的陈述。逃跑是不够的!您必须检查php日志和apache日志。可能是其他原因造成的问题,并且您的代码在安装后正常运行。我还必须激活该zip存档。这可以通过在Cpanel中选择PHP版本并勾选zip之外的复选框来实现。