FPDF致命错误

FPDF致命错误,pdf,pdf-generation,require,fpdf,Pdf,Pdf Generation,Require,Fpdf,我正在尝试测试FPDF的实现。下面是我正在测试的代码,但它不断给我错误:“致命错误:在第5行的/home4/fwall/public_html/create-press-release.php中找不到类'FPDF'。这是我调用下面代码的页面的URL 我已经验证了FPDF的php文件是从正确的位置需要的,并且它仍然在发生。有人知道发生了什么事吗 require(__DIR__.'/fpdf.php'); //The fpdf folder is in my root directory. //c

我正在尝试测试FPDF的实现。下面是我正在测试的代码,但它不断给我错误:“致命错误:在第5行的/home4/fwall/public_html/create-press-release.php中找不到类'FPDF'。这是我调用下面代码的页面的URL

我已经验证了FPDF的php文件是从正确的位置需要的,并且它仍然在发生。有人知道发生了什么事吗

require(__DIR__.'/fpdf.php'); //The fpdf folder is in my root directory.

//create a FPDF object
$pdf=new FPDF();

//set document properties
$pdf->SetAuthor('Lana Kovacevic');
$pdf->SetTitle('FPDF tutorial');

//set font for the entire document
$pdf->SetFont('Helvetica','B',20);
$pdf->SetTextColor(50,60,100);

//set up a page
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');

//insert an image and make it a link
//$pdf->Image('logo.png',10,20,33,0,' ','http://www.fpdf.org/');

//display the title with a border around it
$pdf->SetXY(50,20);
$pdf->SetDrawColor(50,60,100);
$pdf->Cell(100,10,'FPDF Tutorial',1,0,'C',0);

//Set x and y position for the main text, reduce font size and write content
$pdf->SetXY (10,50);
$pdf->SetFontSize(10);
$pdf->Write(5,'Congratulations! You have generated a PDF.');

//Output the document
$pdf->Output('example1.pdf','I'); 
这一行:

require('http://siteurlredacted.com/fpdf/fpdf.php');
可能不会做你期望的事。该请求将使远程服务器“执行”fpdf.php,返回一个空白页面,您的脚本将包含一个空文件。这就是为什么它找不到任何要加载的类

您应该下载FPDF并将该文件放在文件系统中,在该文件系统中,脚本无需HTTP请求即可访问该文件。您可以尝试将fpdf.php放入项目中


希望这有帮助。

谢谢。我想你的意思是把它称为相对文件?我也试过,但运气不好。我已经用现在的内容更新了这个问题。@Eckstein我在项目内的目录下下载了fpdf之后,尝试了您的代码。只需将require上的绝对路径更改为
require('./fpdf/fpdf.php')
就可以了,没关系,您是对的。我没有正确要求相对路径。一旦我弄明白了,它就成功了。上面的工作解决方案。太好了!祝你的项目好运。