简体   繁体   中英

How to refer library in subfolder in php

I have the line $pdf = new FPDF(); which works if the FPDF library is in the root directory, but how do I use it if the library is in a sub folder. I have tried

$pdf = new mySubfolder/FPDF();

but it doesnt work. Any help please?

Try this, only include with directory structure.

require_once("mySubfolder/fpdf.php");
$pdf = new FPDF();

You could use namespaces (PHP 5 >= 5.3.0, PHP 7)

<?php
   namespace myMainFolder;

   use mySubFolder\PDF;

   $pdf = new PDF();

   var_dump($pdf);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM