Fillable PDF Form with PHP using PDFtk error - php

I am trying to fill out pdf files using a github project that i found on [https://github.com/mrdigitalau/PHP-PDFTK-Tutorial]
Basically there is 2 page, one named: GeneratedPDF that hold code:
<?php
namespace Classes;
if(!defined('ACCESSCHECK')) {
die('Direct access not permitted');
}
use mikehaertl\pdftk\Pdf;
class GeneratePDF {
public function generate($data)
{
try {
$filename = 'pdf_' . rand(2000,1200000) . '.pdf';
$pdf = new Pdf('./test.pdf');
$pdf->fillForm($data)
->flatten()
->saveAs( './completed/' . $filename);
//->send( $filename . '.pdf');
return $filename;
}
catch(Exception $e)
{
return $e->getMessage();
}
}
}
And another page name generate.php that holds this code:
<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
exit;
}
define('ACCESSCHECK', TRUE);
require_once 'vendor/autoload.php';
use Classes\GeneratePDF;
$data = [
'name_field' => $_POST['fname'] .' ' . $_POST['lname'],
'email_field' => $_POST['email'],
'phone_field' => $_POST['phone'],
'enquiry_field' => $_POST['enquiry']
];
$pdf = new GeneratePdf;
$response = $pdf->generate($data);
header('Location: thanks.php?fname=' . $_POST['fname'] . '&link=' . $response);
The problem is every time i try to fill out a pdf I get this error:
Fatal error: Uncaught Error: Class 'Classes\GeneratePDF' not found in C:\xampp\htdocs\generate.php:23 Stack trace: #0 {main} thrown in C:\xampp\htdocs\generate.php on line 23
Any idea the problem here? Thanks in advance

Related

Uploading Image to Parse(Back4App) in PHP

Hello everyone I'm trying to upload an image to parse with PHP. i was able to add the object all the columns works perfectly except the Image Column stays undefined i checked the php.ini (url_fopen:On ;) and the utf-8 charset and many other solutions i thins its a problem of security or Privilege !! Please if you have any useful Ideas share it and Thanks in Advance !!!
Here is my code
<?php
require_once( 'autoload.php' );
// Add the "use" declarations where you'll be using the classes
use Parse\ParseObject;
use Parse\ParseUser;
use Parse\ParseException;
use Parse\ParseFile;
use Parse\ParseCloud;
use Parse\ParseClient;
use Parse\ParseQuery;
try {
$app_id = "xxxxxxxxxxxxxxxxxxxxxx" ;
$rest_key = "xxxxxxxxxxxxxxxxxxxxxx";
$master_key = "xxxxxxxxxxxxxxxxxxxxxx";
ParseClient::initialize( $app_id, $rest_key, $master_key );
ParseClient::setServerURL('https://parseapi.back4app.com', '/');
if(isset($_GET['libelle']) && (isset($_GET['prix']) ) ){
$libelle = $_GET['libelle'];
$prix = $_GET['prix'];
}
if ( isset( $_FILES['image'] ) ) {
$isFileExists = file_exists ($_FILES['image']['tmp_name'] );
$isGoodSize = ($_FILES['image']['size'] < 600000) && ($_FILES['image']['size'] > 0);
if ( $isFileExists && $isGoodSize) {
// save file to Parse
$file = ParseFile::createFromData( file_get_contents( $_FILES['image']['tmp_name'] ), $_FILES['image']['name'] );
$file->save();
//echo 'File URL: ' . $file->getURL() . '';
} else {
echo "Erreur";
}
}
$Prod = ParseObject::create("Produit");
//$Prod = new ParseObject("Produit");
$Prod->set("libelle",$libelle);
$Prod->set("prix",(float)$prix);
if ( isset( $file ) ) {
$Prod->set("image",$file);
}
try {
$Prod->save();
echo 'Object Saved with ID: <strong>' . $Prod->getObjectId() . '</strong>.<br/>';
} catch (ParseException $ex) {
echo 'Failed to create new object, with error message: ' . $ex->getMessage();
}
} catch (ParseException $ex) {
echo $ex->getMessage();
}
?>
I was checking here more about files! Just for help you, the maximum file size is 20MB. You can test with different file sizes.
At releases page on GitHub from Parse PHP SDK, you can check the version 1.2.8 that fixed a error with ParseFiles.

php - Class 'Browscap' not found in

I'm using Browscap downloaded from Github.
So I have a _class.php
require_once dirname(__FILE__) . "/core/CORE.php";
require_once dirname(__FILE__) . "/core/Browscap.php";
// use phpbrowscap\Browscap;
class _class extends CORE {
//put your code here
public function __construct($mysql_setup = null) {
parent::__construct($mysql_setup);
$bc = new Browscap(dirname(__FILE__) . "/../cache"); //this is the error line
$get_browser = $bc->getBrowser(null, true);
$get_browser["HTTP_REFERER"] = $_SERVER["HTTP_REFERER"];
$get_browser["REQUEST_TIME"] = date("Y-m-d H:i:s", $_SERVER["REQUEST_TIME"]);
$this->dbCreateTable();
$user = $_SERVER['REMOTE_ADDR'] . ";" . session_id();
if ($this->insertUser($user) !== false) {
$http_user_id = $this->dbLastInsertID();
foreach ($get_browser as $k => $v) {
if (($type_id = $this->getHttpUserTypeDB($k)) !== false) {
$this->dbInsert("http_user_agent_infos", array("info" => $v, "http_user_agent_id" => $http_user_id, "http_user_agent_type_id" => $type_id));
}
}
}
}
My directory hierarchy is like this
C:\xampp\htdocs\test
classes(folder)
core(folder)
Browscap.php
CORE.php
_class.php
form.php
cache(folder)
browscap.ini
cache.php
php_browscap.ini
The error is
Fatal error</b>: Class 'Browscap' not found in <b>C:\xampp\htdocs\job6b\classes\_class.php</b> on line <b>28</b><br />
I'm not sure where I have my error...or did I put the path wrongly?
Thanks

spl_autoload_reqister classes not getting loaded

I have a folder structure that looks like
base_dir-
Includes.php
Libs-
Database.php
Log.php
Cofing.php
Models-
someClass.php
Scheduled-
test.php
My Includes.php has
spl_autoload_register(NULL, FALSE);
spl_autoload_extensions('.php, .class.php, lib.php');
function libLoader($name) {
$file = 'Libs/' . $name . '.php';
if (!file_exists($file)) {
// throw new Exception("Error Loading Library: $file does not exists!", 1);
return FALSE;
}
require_once $file;
}
function modelLoader($name) {
$file = 'Models/' . $name . '.php';
if (!file_exists($file)) {
// throw new Exception("Error Loading Library: $file does not exists!", 1);
return FALSE;
}
require_once $file;
}
spl_autoload_register('libLoader');
spl_autoload_register('modelLoader');
My someClass.php has
require_once '../Includes.php';
class someClass extends Database
{
public function __construct() { return 'hello world'; }
}
And test.php has
require_once '../Includes.php';
try {
$loads = new someClass();
} catch (Exception $e) {
echo "Exception: " . $e->getMessage();
}
When I run test.php I get someClass not found on .../Scheduled/test.php
Does spl works with extended classes like someClass.php or do I need to include the class to be exended?
And why it wouldnt find someClass.php?
Thanks
Change
$file = 'Models/' . $name . '.php';
to
$file = __DIR__ . '/Models/' . $name . '.php';
in your models autoloader (and the equivalent in your libLoader) to ensure that it's searching from the correct directory, and not the directory where your test.php file is located

reader class not found in GeoIP2

I am trying to install Maxmind's GeoIP2. I did everything by their instructions and I still get this annoying error:
Fatal error: Class 'GeoIp2\Database\reader' not found in C:\Program Files\*\*\localweb\GeoIp2\index.php on line 19
this is how the script looks like inside index.php:
<?php
require_once 'vendor/autoload.php';
use GeoIp2\Database\reader;
// This creates the Reader object, which should be reused across
// lookups.
$reader = new Reader('C:/Program Files/*/*/localweb/GeoIp2/Database/GeoLite2-Country.mmdb');
$record = $reader->country('128.101.101.101');
?>
Anybody can help please ?
This worked for me thanks #Greg Oschwald!
Since I'm not using composer, my code now is:
<?php
require 'geoip2.phar';
try {
$reader = new GeoIp2\Database\Reader('GeoLite2-City.mmdb');
$record = $reader->city('128.101.101.101');
print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['zh-CN'] . "\n"); // '??'
print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'
print($record->city->name . "\n"); // 'Minneapolis'
print($record->postal->code . "\n"); // '55455'
print($record->location->latitude . "\n"); // 44.9733
print($record->location->longitude . "\n"); // -93.2323
} catch (Exception $e) {
echo 'Could not open Phar: ', $e;
}
Took that phar file from https://github.com/maxmind/GeoIP2-php/releases
Try changing:
use GeoIp2\Database\reader;
to:
use GeoIp2\Database\Reader;
Try to up php version to 7.1.33 or higher

HTML to PDF Creation in Cakephp

Path : Vendor/dompdf
I am getting Fatal error: Class 'DOMPDF' not found in C:\wamp\www\sms_app\app\Controller\SentMessagesController.php on line 313.
Why i am getting error? This is my code:
function example()
{
//App::import('Vendor','dompdf',array('file'=>'dompdf'.DS.'dompdf_config.inc.php'));
require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
try{
$this->dompdf = new DOMPDF();
}
catch (Exception $e)
{
echo $e;
}
$papersize = "legal";
$orientation = 'landscape';
$this->dompdf->load_html($html);
$this->dompdf->set_paper($papersize, $orientation);
$this->dompdf->render();
$output = $this->dompdf->output();
file_put_contents('Brochure.pdf', $output);
}
The error message pretty clearly tells you what is wrong. Check the file(s) you include if the class exists in that file, I doubt it is there. If not figure out in which file the class is and load that file. Check how Dompdf is loading its files.
This error clear says you missing a class so please check how actually importing class in your code.

Categories