is this the right php header for pdftk - php

I'm writing a very basic catenation script and lifted this straight off the pdftk 0.10.0 packagist site:
use mikehaertl\pdftk\Pdf;
// Extract pages 1-2 into a new file
$pdf = new Pdf('sourcefile.pdf');
$result = $pdf->cat(1, 2)
->saveAs('newfile.pdf');
if ($result === false) {
$error = $pdf->getError();
}
But I'm getting this error:
Fatal error: Uncaught Error: Class "mikehaertl\pdftk\Pdf" not found in C:\PHP8\index.php:7 Stack trace: #0 {main} thrown in C:\PHP8\index.php on line 7
All the sample scripts I've seen have that same header. I'm sure it's something really basic that I'm not seeing here.

Since the error is showing the Class not found, it would make me initially think that the package wasn’t installed in your project. If you run composer require mikehaertl/php-pdftk, does that get you rolling?
If you’re not familiar with Composer, here’s a quick guide to getting started: https://packagist.org/

Apparently, when installed via composer, the pdftk.exe file is not downloaded for some reason. I downloaded it manually from the github page and referred to it in the header.

Ok, finally found the answer. You need to install pdftk beforehand as packagist does not automatically pull it for you.

Related

PHP error calling a function from a package

I am new to php and have just installed my first package via composer. I'm now trying to call a function from the package I installed as follows:
<?php
require_once 'vendor/autoload.php';
$value = 1;
$aws = AmazonGiftCode::make()->buyGiftCard($value);
echo $aws;
?>
But I get the following error:
PHP Fatal error: Uncaught Error: Class 'AmazonGiftCode' not found in
/public_html/php/test.php:4 Stack trace:
#0 {main} thrown in /public_html/php/test.php on line 4
Based on my (albeit limited) experience with other languages, I'm guessing I have to load the package that contains the class first. The package folder is in the same directory as the test.php file, in the subfolder vendor/kamerk22/AmazonGiftCode/. But I think this is where I don't know enough to troubleshoot it based on the information I could find.
Your directory structure should look like this.
test.php
composer.json
vendor
└───autoload.php
└───kamerk22
└───AmazonGiftCode
Make sure you installed the package using composer, and not by downloading it.
I'm guessing I have to load the package that contains the class first.
Unlike what you would normally expect when importing stuff, when using composer you only have to import the autoload.php file, and composer will take care of loading other packages as needed. By as needed what I mean is that as soon as composer sees you use the AmazonGiftCode class it will import the AmazonGiftCode package, but if one of your REST endpoints doesn't use anything from the AmazonGiftCode package it won't ever load it. This allows you to not have to worry about slowing down the entire application when you want to use a composer package for only a few endpoints. At least that's the way I understand how composer works.
Just run composer dump-autoload once and the class should known then.
You could also get verbose and use kamerk22\AmazonGiftCode\AmazonGiftCode;
But that AmazonGiftCode looks quite Laravel specific... that's why it may still fail, even if it may be found by auto-load. One needs to setup Laravel framework in the first place; just see this query (just in case if you may wonder where all these missing classes may come from).

installing Google Client Library for Google Analtics PHP

first of all I am new to this topic, so I hope my question is not too stupid.
I want my website to have PHP access to Google Analytics metrics. I followed every step of this description from google. Unfortunately when I upload everything on my server and try to run the test-site, I always get the following error-message:
Fatal error: Uncaught exception 'Exception' with message 'This library
must be installed via composer or by downloading the full package. See
the instructions at
https://github.com/google/google-api-php-client#installation.' in
/home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php:14
Stack trace: #0
/home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(8):
require_once() #1
/home/users/myftp/dev.mywebsite.com/dashboard/HelloAnalytics.php(104):
getService() #2 {main} thrown in
/home/users/myftp/dev.mywebsite.com/dashboard/google-api-php-client-master/src/Google/autoload.php
on line 14
So apparently there is something wrong with the embedding of the Google client library. In the error message it says I have to use Composer, but in the GitHub documentation they say, manual download would be fine as well. I think in the end this shouldn't make any difference? I am not familiar with composer or GitHub, this is why i downloaded it manually.
I uploaded it on the server and put it into the same directory like the HelloAnalytics.php. I address it in HelloAnalytics.php via
require_once 'google-api-php-client-master/src/Google/autoload.php'
From the looks of it you are using the wrong autoloader.
src/Google/autoload.php looks for the composer autoloader and if it doesn't exist it throws the exception you are getting. Since you didn't install using Composer it is not found and that exception is thrown.
If you clone the repository using git you will have the correct SPL autoloader. If you download the package it uses the composer autoloader.
Try downloading using:
git clone -b v1-master https://github.com/google/google-api-php-client.git
Or switch to the v1-master branch and use this autoloader instead. You will see that file differs between the master branch and the v1-master branch.
to avoid AUTOLOADer error, install MASTER-V1 version:
https://github.com/google/google-api-php-client/tree/v1-master
p.s. if you will get other error, then ensure that you have correctly included the "SERVICE EMAIL" (that is like: xxxxxx#analytics-xxxxx.iam.gserviceaccount.com ).

Net_GeoIP returns a fatal error

I have installed net_geoip on my web host and am encountering the error Fatal error: Class 'Net_GeoIP' not found in /home/heyitspr/public_html/beta_simplecraft.biz/index.php on line 3 when I run the script that is posted below:
$geoip = Net_GeoIP::getInstance('GeoIP.dat', Net_GeoIP::SHARED_MEMORY);
$country_name = $geoip->lookupCountryName($_SERVER['REMOTE_ADDR']);
print_r ($country_name);
I am new to installing plugins with apache so please explain it in simpler terms. Thanks
Seems like you have not included your GeoIP library. Try including it on your index.php code
include_once('GeoIP.php');

How can I use the newly revamped Dropbox-PHP API?

I would like to use the Dropbox-PHP API that has recently come under development again. It is located here: http://code.google.com/p/dropbox-php/
I did cloned it with hg clone https://dropbox-php.googlecode.com/hg/ dropbox-php and I get this file structure:
Dropbox/API.php
Dropbox/autoload.php
Dropbox/Exception/Forbidden.php
Dropbox/Exception/NotFound.php
Dropbox/Exception/OverQuota.php
Dropbox/Exception/RequestToken.php
Dropbox/Exception.php
Dropbox/OAuth/PEAR.php
Dropbox/OAuth/PHP.php
Dropbox/OAuth/Zend.php
Dropbox/OAuth.php
examples/accountinfo.php
examples/createaccount.php
examples/download_image.php
examples/getmetadata.php
examples/oauth_workflow.php
examples/uploading.php
But I get this error when trying to run accountinfo.php (or example):
Warning: include(Dropbox/autoload.php) [function.include]: failed to open stream
No such file or directory in dropbox-api/examples/accountinfo.php on line 7
Right, so then I move the Dropbox folder inside of where all the example files are and still get an error message:
Fatal error: Uncaught exception 'Dropbox_Exception' with message 'The OAuth class
could not be found! Did you install and enable the oauth extension?' in
examples/Dropbox/OAuth/PHP.php:36 Stack trace: #0 examples/accountinfo.php(9):
Dropbox_OAuth_PHP->__construct('', '') #1 {main} thrown in
examples/Dropbox/OAuth/PHP.php on line 36
So I'm obviously not doing something right but I have no idea what.
Also saw on the site where it has instructions on installing:
pear channel-discover pear.dropbox-php.com
pear install dropbox-php/Dropbox-alpha
I ran those two commands and it still won't work. I don't usually have any problems coding in PHP but the lack of documentation is a little frustrating.
Update
As noted in the accepted answer below my main problem was not having oAuth installed on the system. I'm running OS X 10.6 - if someone can provide some clear and easy instructions on how to build / install this to work with XAMPP / PHP 5.3 I will accept your answer. I've tried the articles online about using homebrew and such but these are flaky and do not seem to work for me. Guessing I will have to build / install it from scratch.
The Dropbox folder needs to be inside one of the folders in your include_path.
Edit:
Also oauth needs to be "installed" on the system and included in php.ini (when you do phpinfo() oAuth should show up as a module). then things should work.

Smarty Modifiers PHP

I am trying to get Smarty setup and working, so that I can install the open-source project here
http://sourceforge.net/projects/assign-calc/
After following the install instructions, I get stuck with the following error message
<b>Fatal error</b>: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/var/www/dev/calendar/skins/rpc/tmpl/page/rpc_header.tpl" on line 5 " {$application.long_name|escape}" unknown modifier "escape"' in /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php:423
Stack trace:
#0 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_compile_private_modifier.php(62): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown modifie...', 5)
#1 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(279): Smarty_Internal_Compile_Private_Modifier->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), Array, NULL, NULL)
#2 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(123): Smarty_Internal_TemplateCompilerBase->callTagCompiler('private_modifie...', Array, Array)
#3 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_compile_private_print_expression.php(68): Smarty_Internal_TemplateCompilerBase in <b>/usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php</b> on line <b>423</b><br />
After a bit of googling, I think the problem is being cause by Smarty not reading the escape modifier in the plugins directory.
How do I resolve this? I've even tried 777 the permissions on smarty, but that hasnt change anything...
Have you loaded the smarty configuration correctly? In particular, have you setted correctly the plugin path, through the command
$smarty->addPluginsDir('path/to/plugins');
?
I'm the developer of the Research Project Calculator, and found this SO question while researching the same problem for another user. The code has only been in the wild for a few weeks and we're discovering some of these things as other institutions install it.
I was able to get it running for the other user by explicitly calling parent::__construct(); before anything else in the inc/rpc_smarty.inc.php class constructor. I'll post a new release shortly, but for now you should just be able to patch that constructor as below.
Please feel free to contact me via the link in the project's installation instructions wiki page if you have more questions or run into other problems.
public function __construct($config)
{
parent::__construct();
$this->config = $config;
...
...
}
An absolute system path is the fastest and safest approach. You can use relative paths, but be certain the php include_path contains what is needed to find it. You could also use SMARTY_DIR to base your path from.

Categories