简体   繁体   中英

Configuring TCPDF for use on local server with MAMP

I wish to use TCPDF so have downloaded the code and am having trouble using it.

I work on Mac locally using MAMP.

My project is stored in:

/Applications/MAMP/htdocs/my-project-title

I place the whole tcpdf folder in my project so it's location is:

/Applications/MAMP/htdocs/my-project-title/tcpdf

I found a file tcpdf_include.php in the examples directory so I pulled it out and placed it also in the tcpdf folder:

/Applications/MAMP/htdocs/my-project-title/tcpdf/tcpdf_include.php

So I wasn't sure if this was right but it seemed so. I then referenced tcpdf_include.php in my script: require_once('../tcpdf/tcpdf_include.php'); and it found the file all good.

Now I was confused as to how exactly this was working. I ran an example and got nothing and error log states:

[04-Nov-2015 16:27:36 Europe/Berlin] PHP Fatal error: Class 'TCPDF' not found in /Applications/MAMP/htdocs/my-project-title/scripts/myscript.php on line 15

... so it seems like it's just not running the script. I went to the config file to attempt to edit some stuff there.

I changed the following in the config file:

define ('K_PATH_MAIN',  '/MAMP/htdocs/my-project-title/tcpdf/');
define ('K_PATH_URL', 'http://localhost:8888/my-project-title/tcpdf/');

These are now inline with how my project is set up. But I'm still getting the above error when I try to run the script.

What am I missing are there any examples of how to properly configure TCPDF?

Try this:

  1. Store the script you are trying to run in /Applications/MAMP/htdocs/my-project-title , eg. /Applications/MAMP/htdocs/my-project-title/test.php
  2. In that script, just do require_once('tcpdf/tcpdf.php'); (I'm assuming the tcpdf folder is still sitting here: /Applications/MAMP/htdocs/my-project-title/tcpdf )
  3. You should then be able to instantiate an instance of the TCPDF class.

You shouldn't need to worry about anything else - it should just work. If it doesn't, try creating a fresh folder in your htdocs folder, drop a fresh copy of tcpdf in there and try again, just in case you've moved something in your current version that is messing things up.

To be clear, this is what test.php should contain:

require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF();

Good luck!

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