【发布时间】:2020-02-24 14:48:13
【问题描述】:
所以我正在制作一个网站,允许用户从 xlsx 文件表中读取并下载所有数据,每个数据都以单独的 pdf 格式下载,这是代码
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
// Load Composer's autoloader
require 'vendor/autoload.php';
$file_name="";
//index.php
$message = '';
require_once __DIR__.'/../src/SimpleXLSX.php';
echo '<h1>XLSX to HTML</h1>';
if (isset($_FILES['file'])) {
if ( $xlsx = SimpleXLSX::parse( $_FILES['file']['tmp_name'] ) ) {
$filen=$_FILES['file']['tmp_name'];
echo '<h2>'.$xlsx->sheetName($_POST['sh']-1).'</h2>';
echo '<table border=1>';
$dim = $xlsx->dimension();
$num_cols = $dim[0];
$num_rows = $dim[1];
foreach ( $xlsx->rows($_POST['sh']-1) as $k => $r ) {
// if ($k == 0) continue; // skip first row
echo '<tr>';
if ($k == 0) echo '<td>' .$r[ 0 ]. '</td>';
else
echo '<td>' .substr_replace($r[ 0 ],"",strripos($r[ 0 ]," ")). '</td>';
echo '<td>' .$r[ 1 ]. '</td>';
echo '<td>' .$r[ 2 ]. '</td>';
echo '<td>' .$r[ 4 ]. '</td>';
echo'<td>' . $r[ 5 ]. '</td>';
echo'<td>' . $r[ 7 ]. '</td>';
echo'<td>' .$r[ 8 ] . '</td>';
echo '</tr>';
if ($k != 0) // skip first row
{$date = substr_replace($r[0], "", strripos($r[0], " "));
$factname = $r[1];
$name = $r[2];
$email = $r[4];
$phone = $r[5];
$post = $r[7];
$pack = $r[8];
echo $name;
if ($pack == '90') $garanti = '30 jours';
else if ($pack == '190') $garanti = '6 mois';
else if ($pack == '290') $garanti = '12 mois';
else if ($pack == '390') $garanti = '2 ans';
else if ($pack == '490') $garanti = '3 ans';
else if ($pack == '590') $garanti = '5 ans';
sendmail();
echo'<td>telecharger</td>';}
// echo "telecharger";
}
echo '</table>';
echo '</tr>';
}
echo '</table>';
}
else {
echo SimpleXLSX::parseError();
}
if(isset($_POST['charge'])) {
if (isset($_FILES['file'])) {
if ($xlsx = SimpleXLSX::parse($_FILES['file']['tmp_name'])) {
foreach ($xlsx->rows($_POST['sh']-1) as $k => $r) {
if ($k == 0) continue; // skip first row
$date = substr_replace($r[0], "", strripos($r[0], " "));
$factname = $r[1];
$name = $r[2];
$email = $r[4];
$phone = $r[5];
$post = $r[7];
$pack = $r[8];
if ($pack == '90') $garanti = '30 jours';
else if ($pack == '190') $garanti = '6 mois';
else if ($pack == '290') $garanti = '12 mois';
else if ($pack == '390') $garanti = '2 ans';
else if ($pack == '490') $garanti = '3 ans';
else if ($pack == '590') $garanti = '5 ans';
sendmail();
echo "telecharger";
}
}
echo "telecharger";
}
}
echo '<h2>Upload form</h2>
<form method="post" enctype="multipart/form-data">
*.XLSX <input type="file" name="file" />
<input placeholder="sheet number" name="sh" type="number" required>
<input type="submit" value="Parse" />
</form>';
function sendmail()
{
global $name;
global $file_name;
$file_name="";
echo $file_name;
include('pdf.php');
$pdf = new Pdf();
$file_name = "ORDER-".$name . '.pdf';
$html_code = '<link rel="stylesheet" href="bootstrap.min.css">';
$html_code .= fetch_customer_data();
$pdf->load_html($html_code);
$pdf->render();
$file = $pdf->output();
file_put_contents($file_name, $file);
// $pdf->stream($file_name) ->
}
这是 pdf.php 文件
<?php
//pdf.php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
class Pdf extends Dompdf{
public function __construct(){
parent::__construct();
}
}
?>
我想同时下载所有 pdf,但它只下载第一个并显示此错误
( ! ) Fatal error: Cannot declare class Pdf, because the name is already in use in C:\wamp64\www\vucrm\xl\simplexlsx-master\examples\pdf.php on line 0
我尝试在 sendmail 函数的末尾添加exit(),但这只会下载第一个并且没有显示其他数据或错误
谁能帮忙提前谢谢
【问题讨论】:
-
是你自己的课,还是供应商的课?
-
这是供应商的