doutonghang2761 2015-11-04 15:33
浏览 88

配置TCPDF以在具有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?

  • 写回答

1条回答 默认 最新

  • duancu4731 2015-11-04 21:57
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题