PHPExcel_IOFactory :: load($ target_file)在本地主机上工作,但不在服务器上

在将excel文件导入到服务器时,它将不起作用或不会给出任何错误。

在这里,究竟发生了什么事情,首先是在导入excel文件的时候,首先我将该file upload到服务器,然后我使用该文件将数据导入数据库。 文件正确地上传到服务器,但它不会继续工作。 我有debugging该文件,并知道这一点

PHPExcel_IOFactory::load($target_file); is not working 

请帮忙。谢谢

代码在这里:

  <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> function closeWin() { myWindow.close(); } </script> </head> <body> <?php session_start(); function GetFileExtension($imagetype) { if (empty($imagetype)) return false; switch ($imagetype) { case 'xlsx': return '.xlsx'; case 'xls': return '.xls'; default: return false; } } libxml_use_internal_errors(true); //include the following 2 files include './config.php'; require '../../PHPExcel_1.8.0/Classes/PHPExcel.php'; require_once '../../PHPExcel_1.8.0/Classes/PHPExcel/IOFactory.php'; $target_dir = './uploads/'; $product = filter_input(INPUT_POST, 'product'); $username = $_SESSION['pman']; $target_file = $target_dir . basename($_FILES["userfile"]["name"]); $filename = basename($_FILES["userfile"]["name"]); $file_type = pathinfo($filename, PATHINFO_EXTENSION); $Type_status = true; $ext = GetFileExtension($file_type); if ($ext == FALSE) { echo 'This File Type is not Supported'; echo 'Please use Excel sheets with extension *.xlsx or *.xls'; echo '<a id="click" href="javascript:window.close()">Close this window</a>'; } else { if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_file)) { echo 'File Uploaded'; } else { echo 'error'. mysql_error(); } $objPHPExcel = PHPExcel_IOFactory::load($target_file); foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { $worksheetTitle = $worksheet->getTitle(); $highestRow = $worksheet->getHighestRow(); // eg 10 $highestColumn = $worksheet->getHighestColumn(); // eg 'F' if ($highestColumn != 'L') { echo 'This File is as per given Standered'; echo 'Please Check Template for perticular standards'; echo '<a id="click" href="javascript:window.close()">Close this window</a>'; break; } $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); $nrColumns = ord($highestColumn) - 64; echo "<br>The worksheet " . $worksheetTitle . " has "; echo $nrColumns . ' columns (A-' . $highestColumn . ') '; echo ' and ' . $highestRow . ' row.'; echo '<a id="click" href="javascript:window.close()">Close this window</a>'; echo '<br>Data: <table border="1"><tr>'; for ($row = 1; $row <= $highestRow; ++$row) { $valarray = array(); echo '<tr>'; for ($col = 0; $col < $highestColumnIndex; ++$col) { $cell = $worksheet->getCellByColumnAndRow($col, $row); $valarray[] = $cell->getValue(); $dataType = PHPExcel_Cell_DataType::dataTypeForValue($valarray[$col]); echo '<td>' . $valarray[$col] . '</td>'; } if ($row > 1) { if (strtolower($valarray[2]) == 'prepaid' || strtolower($valarray[2]) == 'postpaid') { if ($valarray[0] == "") { $Type_status = false; } else { } } else { $Type_status = false; } } echo '</tr>'; } echo '</table>'; } $count = 0; if ($Type_status == true) { if ($highestColumn != 'L') { } else { $upd = null; $cmt = null; $rev = 'Pending'; for ($row = 2; $row <= $highestRow; ++$row) { $val = array(); for ($col = 0; $col < $highestColumnIndex; ++$col) { $cell = $worksheet->getCellByColumnAndRow($col, $row); $val[] = $cell->getValue(); } $testcaseid = '1234' . rand(50, 5000); $sql_insert = $conn->prepare("INSERT INTO tmtool.testcase_master (`Testcase_id`,`Testcase_title`, `Precondition`, `Product_id`, `Subscriber_type`, `Created_by`, `Activation_mode`, `Testcase_desc`, `Date_created`, `Test_step`, `Expected_result`, `Category`, `Sub_category`,`Language`,`Priority`, `Updated_date`, `Comment`, `Review`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $sql_insert->bind_param('ssssssssssssssssss', $testcaseid, $val[0], $val[1], $product, $val[2], $username, $val[3], $val[4], $val[5], $val[6], $val[7], $val[8], $val[9], $val[10], $val[11], $upd, $cmt, $rev); if ($sql_insert->execute()) { $sql_insert->close(); $count++; } else { die(mysqli_error($conn)); } } echo $count . 'Test cases has been Imported to the Database'; echo '<a id="click" href="javascript:window.close()">Close this window</a>'; } } else { echo 'Some Testcase dont have Subscriber Type or Testcase Title ...It is a Mandatory Field. Can not be Empty'; echo '<a id="click" href="javascript:window.close()">Close this window</a>'; } } ?> </body> 

这可能是文件大小的问题。 也许PHPExcel无法读取您的文件,如果它是巨大的。 这是清除疑惑的好地方: https : //phpexcel.codeplex.com/workitem/list/basic

我发现了这个问题。问题在于我的库。我已经使用了phpexcel库版本1.8.0。 但仍然有一些更新发生后的话。

我以前使用的是不能正确处理.xlsx文件,但可以使用.xls。

我遇到的问题是:当我上传.xlsx文件时,它会自动将其转换为.xls。 而不能处理。 解决scheme:我已经更新了我的PHPExcel库,因此对于.xlsx和.xls都能正常工作。