[英]Fatal error: Class 'TCPDF' not found in another path
當我們點擊鏈接時,我們想以Pdf格式下載php頁面數據 。
所以我們從官方的git hub鏈接下載了TCPDF
我們將提取的文件夾復制到路徑:“ / var / www / html / sbdev2 / php / site6 ”
當我們在瀏覽器中運行示例代碼時: http : //sbdev2.kidsdial.com : 81 / php / site6 / tcpdf / examples / example_011.php我們可以下載pdf。
當我們在另一條路徑中嘗試相同的代碼時: http Fatal error: Class 'TCPDF' not found
,我們收到錯誤為“ Fatal error: Class 'TCPDF' not found
”in Fatal error: Class 'TCPDF' not found
line: class MYPDF擴展了TCPDF {
我檢查了鏈接,但這對我不起作用。
我也檢查了link2並通過composer安裝了TCPDF,如下圖所示。 但仍然存在錯誤。
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;
}
}
EDIT2
只有當我在/ 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(... INSTALED DIRECTORY ... \\ tcpdf.php'); 它會工作,一切順利
在示例001中更改了此行:
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
進入:
// Include the main TCPDF library (search for installation path).
require_once('**C:\wamp\www\pdf2\tcpdf\tcpdf.php**');
它適用於WAMP
。
希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.