gpt4 book ai didi

php - fatal error :在另一个路径中找不到类“TCPDF”

转载 作者:行者123 更新时间:2023-12-04 22:38:08 25 4
gpt4 key购买 nike

当我们单击链接时,我们要下载Pdf格式的php页面数据。

因此,我们从官方git hub link下载了TCPDF

我们将提取的文件夹复制到路径:“ / var / www / html / sbdev2 / php / site6”

当我们在浏览器中运行示例代码:http://sbdev2.kidsdial.com:81/php/site6/tcpdf/examples/example_011.php时,我们可以下载pdf。

当我们在另一条路径http://sbdev2.kidsdial.com:81/php/site6/example_011.php中尝试相同的代码时,在行中出现“ Fatal error: Class 'TCPDF' not found in”错误:类MYPDF扩展了TCPDF {

我检查了link,但这对我不起作用。

我也检查了link2并通过composer安装了TCPDF,如下图。但仍然存在该错误。

enter image description here

example_011.php

require_once('tcpdf_config.php');

// extend TCPF with custom functions
class MYPDF extends TCPDF {

// Load table data from file
public function LoadData($file) {
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line) {
$data[] = explode(';', chop($line));
}
return $data;
}

// Colored table
public function ColoredTable($header,$data) {
// Colors, line width and bold font
$this->SetFillColor(255, 0, 0);
// Header
$w = array(40, 35, 40, 45);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(224, 235, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
foreach($data as $row) {
$this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
$fill=!$fill;
}
$this->Cell(array_sum($w), 0, '', 'T');
}
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 011', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 12);

// add a page
$pdf->AddPage();

// column titles
$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. (thousands)');

// data loading
$data = $pdf->LoadData('data/table_data_demo.txt');

// print colored table
$pdf->ColoredTable($header, $data);

// ---------------------------------------------------------

// close and output PDF document
$pdf->Output('example_011.pdf', 'I');


编辑

tcpdfconfig.php

require_once('config/tcpdf_config_alt.php');

// Include the main TCPDF library (search the library on the following directories).
$tcpdf_include_dirs = array(
realpath('../tcpdf.php'),
'/usr/share/php/tcpdf/tcpdf.php',
'/usr/share/tcpdf/tcpdf.php',
'/usr/share/php-tcpdf/tcpdf.php',
'/var/www/tcpdf/tcpdf.php',
'/var/www/html/tcpdf/tcpdf.php',
'/usr/local/apache2/htdocs/tcpdf/tcpdf.php'
);
foreach ($tcpdf_include_dirs as $tcpdf_include_path) {
if (@file_exists($tcpdf_include_path)) {
require_once($tcpdf_include_path);
break;
}
}


编辑2

仅当我在/ var / www / html / sbdev2 / php / site6 / tcpdf /文件夹示例的子文件夹中包含文件时,它才起作用:

/var/www/html/sbdev2/php/site6/tcpdf/example1
/var/www/html/sbdev2/php/site6/tcpdf/example1


如果我将示例文件夹的内容复制到另一个路径,请说:
/ var / www / html / sbdev2 / php / site6 /它根本不起作用.....

最佳答案

我也遇到了这个问题,终于找到了解决方案。
一切都很好,让每个文件都只保留其原始路径,只需要打开tcpdf_include.php并包含文件tcpdf.php,仅此而已!
require_once(...安装目录... \ tcpdf.php');
一切都会好的

关于php - fatal error :在另一个路径中找不到类“TCPDF”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41298752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com