I have started experimenting with codeigniter and pdfs. I'm using the latest version of both. For some reason, i'm getting this error when trying to render the pdfs:
Warning: require_once(C:\Users\Manfred\Dropbox\Web\Alodu\application\helpers\dompdf/include/ci_exceptions.cls.php) [function.require-once]: failed to open stream: No such file or directory in C:\Users\Manfred\Dropbox\Web\Alodu\application\helpers\dompdf\dompdf_config.inc.php on line 208
Fatal error: require_once() [function.require]: Failed opening required 'C:\Users\Manfred\Dropbox\Web\Alodu\application\helpers\dompdf/include/ci_exceptions.cls.php' (include_path='.;C:\php\pear') in C:\Users\Manfred\Dropbox\Web\Alodu\application\helpers\dompdf\dompdf_config.inc.php on line 208
Code used is:
function pdf()
{
$this->load->helper(array('dompdf', 'file'));
// page info here, db calls, etc.
/*
$data=array(
"$title"=>"Hello!",
"$test_questions"=>"1,2,3,4",
);
*/
$data['test_questions']= "hello";
$html = $this->load->view('pdf/test_ibdp', $data, true);
$filename="Test".$data['test_questions'];
pdf_create($html, $filename);
write_file('name', $data);
}
And the helper:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function pdf_create($html, $filename, $stream=TRUE)
{
require_once("dompdf/dompdf_config.inc.php");
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper("a4", "portrait" );
$dompdf->render();
$dompdf->stream($filename . ".pdf");
}
?>
and the view (pure HTML)
<html>
<head>
<title>Hello!</title>
</head>
<body>
<h1>HelloAgain</h1>
</body>
</html>
Any suggestions? I'm not that experienced in PHP and i'm quite confused. I just re-downloaded the library, i've tried keeping it really simple by stripping away extras in my code. Nothing seems to work. any help would be great :)
This is a class autoloader issue. Which version of DOMPDF do you use? I think dompdf 0.5 had a problem when integrated inside a framework like CI.
The 0.6 version doesn't have this probleme anymore, and if the problem persists, write
define("DOMPDF_AUTOLOAD_PREPEND", true)
in dompdf_config.custom.inc.php.
The error is saying the path below is not correct. Recheck the path
require_once("dompdf/dompdf_config.inc.php");
Path to the file is incorrect.
C:\Users\Manfred\Dropbox\Web\Alodu\application\helpers\dompdf/include/ci_exceptions.cls.php
You can use DIRECTORY_SEPARATOR.
Correct the dompdf file path. Also remove this line of code:
write_file('name', $data);
The following line is enough:
pdf_create($html, $filename);
Related
Hi I'm a Amateur programer and I need help for my web's programer subject. I'm trying to link this js but on the page show me this on the top Warning: file_get_contents(script404.js): Failed to open stream: No such file or directory in C:\xampp\apps\wordpress\htdocs\wp-content\themes\villanueva-s_theme-brown_nights-\404.php on line 58
<?php
$script = file_get_contents('script404.js');
echo "<script>".$script."</script>";
?>
You must have an invalid path.
You could use __DIR__.'/script404.js' if this file is in the same folder as script you running.
See Evert's answer in Why include __DIR__ in the require_once?
You can just use:
echo "<script src=\"script404.js\"></script>";
Or, you should point to the right directory, like:
$script = file_get_contents('C:/path/to/script404.js');
echo "<script>".$script."</script>";
Or, I wouldn't advice you to do this, but if it is in the same directory:
$script = file_get_contents('./script404.js');
echo "<script>".$script."</script>";
Good afternoon to everyone.
For the past 3 days, I've been struggling with PHP's Autoloading features, which aims to simplify and unify a program's class files, all located in one executing file. For the context, I am currently learning the OOP perspective of PHP from this tutorial videos to not only further understand PHP's OOP understanding before doing a PHP OOP project from college, but also to try to create my own PHP program, so do ELI5 about the solution to me, please.
From what I've learned from the following videos: Video 1 and Video 2, the autoload codes I written from what I've learned appears to work fine, however, it gave two warnings:
Warning: include(/classes/person.php): failed to open stream: No such file or directory in C:\xampp\htdocs\CollegeTimetableApp\includes\autoloader.php on line 12
Warning: include(): Failed opening '/classes/person.php' for inclusion (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\CollegeTimetableApp\includes\autoloader.php on line 12
And, it gave a fatal error message as follows:
Fatal error: Uncaught Error: Class 'person' not found in C:\xampp\htdocs\CollegeTimetableApp\includes\index.php:33 Stack trace: #0 {main} thrown in C:\xampp\htdocs\CollegeTimetableApp\includes\index.php on line 33
I will include downloadable files so that anyone check and verify it with me.
The Autoloader codes on the autoloading file:
<?php
spl_autoload_register(function($className) {
include str_replace("\\","/","\classes").'/'.str_replace('\\',"/",$className).'.php';
});
?>
Simple executing codes on the index file:
<?php
$person1 = new person();
$person1->SetName("Kai");
echo $person1->name;
?>
My questions: what's wrong, how to create a functioning autoload feature, and are there any additional corrections that can be made from my program?
Thank you.
Try including $_SERVER['DOCUMENT_ROOT'] to your path, as well as the sub folder in that folderwhich contains your app.
<?php
spl_autoload_register(function($className) {
$file = $_SERVER['DOCUMENT_ROOT']; // This is the folder you serve files from
$file .= '/CollegeTimetableApp' // This is the folder in which your app lives
$file .= str_replace("\\", "/", "\classes");
$file .= '/'; // Consider using DIRECTORY_SEPARATOR instead
$file .= str_replace('\\', "/", $className);
$file .= '.php';
include $file;
});
?>
I haven't seen any error in my files but when I run my code it shows me the following error:
Warning: require_once(Core.php): failed to open stream: No such file or directory in C:\xampp\htdocs\completed\inc\autoload.php on line 7
Fatal error: require_once(): Failed opening required 'Core.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\completed\inc\autoload.php on line 7
My code is:
classes/Core.php
<?php
class Core {
public function run() {
ob_start();
require_once(Url::getPage());
ob_get_flush();
}
}
inc/autoload.php
<?php
require_once('config.php');
function __autoload($class_name) {
$class = explode("_", $class_name);
$path = implode("/", $class).".php";
require_once($path);
}
index.php
<?php
require_once('inc/autoload.php');
$core = new Core();
$core->run();
I know it's a bit late. I was researching on this because I had the same problem. This is what i tried and it worked for me.
// this code is for the inc/autoload.php file.
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(dirname(__FILE__) . "/config.php");
//require_once(inc/config.php);
function __autoload($className){
$class = explode("_",$className);
$path = implode("/",$class).".php";
require_once($path);
}
Please I just started learning PHP and i stand corrected by you guys.
I hope this helps.
Your Core class is apparently defined at:
C:\xampp\htdocs\completed\classes\Core.php
But you attempt to load this file:
C:\xampp\htdocs\completed\Core.php
It isn't a good idea to build a class auto-loader that works with relative paths*. I suggest you add a prefix here to build an absolute path:
$path = implode("/", $class).".php";
E.g.:
$path = __DIR__ . '/../classes/' . implode("/", $class).".php";
(*) Among other reasons, because relative paths in PHP are relative to the main script (rather than the file when path usage happens) so the source directory depends on what script you load autoload.php from.
I've faced the same problem with yours. I think it's late for you. But may be it's helpful for others.
I didn't included the config.php file in autoload.php file
inc/autoload.php
//require_once('config.php');
I included config.php file in the index.php like this:
index.php
require_once('inc/config.php');
require_once('inc/autoload.php');
And it's worked fore me, I hope this for you, too :). Thanks for your time to read my comment.
because in same folder
require_once('inc/autoload.php');
require_once('config.php');
so.. i think may be should like this
require_once('inc/config.php');
After reading tons of articles and trying out a lot code I coudn't make it work to include a php file form my localhost. And know I cannot even specify a path in javascript code like
xmlhttp.open("GET","/DB/ajax/ajaxDeleteRow.php?q="+commentId,true);
I would like to include the file: drawTableSqlString.php which is in the same folder as my file: CommentTableAndDeleteAjax.php. they are in the folder: C:\xampp\htdocs\DB\ajax
What I tried so far:
1.
echo get_include_path(); and i got displayed: .;C:\xampp\php\PEAR
then I tried to copy my file into that folder --> didn't work.
echo dirname(drawTableSqlString.php);
I got an error:
Notice: Use of undefined constant drawTableSqlString - assumed 'drawTableSqlString' in C:\xampp\htdocs\DB\ajax\CommentTableAndDeleteAjax.php on line 36
3.
after changing path in php.ini from "include_path=".;C:\xampp\htdocs"" to include_path=".;C:\xampp\php\PEAR"
i tried:
include ('\DB\ajax\drawTableSqlString.php');
include ('DB\ajax\drawTableSqlString.php');
gives an error as aways which looks like this:
Warning: include(\DB\ajax\drawTableSqlString.php): failed to open
stream: No such file or directory in
C:\xampp\htdocs\DB\ajax\CommentTableAndDeleteAjax.php on line 33
Warning: include(): Failed opening '\DB\ajax\drawTableSqlString.php'
for inclusion (include_path='.;C:\xampp\htdocs') in
C:\xampp\htdocs\DB\ajax\CommentTableAndDeleteAjax.php on line 33
Based on other forum entries I also tried all that code below but nothing worked:
//************************** include DB connection INFOS
//$xajax_dir = 'C:\\xampp\\htdocs\\DB\\ajax';
//include( $xajax_dir . DIRECTORY_SEPARATOR . 'drawTableSqlString.php' );
//include('./localhost/DB/ajax/CommentTableAndDeleteAjax.php' );
//include('localhost/DB/ajax/CommentTableAndDeleteAjax.php' );
//include('./DB/ajax/CommentTableAndDeleteAjax.php' );
//include('DB/ajax/CommentTableAndDeleteAjax.php' );
//include('C:/xampp/htdocs/localhost/DB/ajax/drawTableSqlString.php' );
//include_path = ('.;C:\xampp\php\PEAR','C:\xampp\htdocs\DB\ajax\drawTableSqlString.php');
//include('127.0.0.1/DB/ajax/CommentTableAndDeleteAjax.php' );
//include('C:\xampp\htdocs\DB\ajax\drawTableSqlString.php');
//FROM http://stackoverflow.com/questions/17003614/including-files-from-include-path-not-working-as-expected
//include_once ('/DB/ajax/drawTableSqlString');
//include_once("C:/xampp/htdocs/DB/ajax/drawTableSqlString.php");
// include __DIR__ . 'drawTableSqlString.php';
// include '../drawTableSqlString.php';
//include('http://127.0.0.1/DB/ajax/CommentTableAndDeleteAjax.php' );
//$xajax_dir = 'C:\\xampp\\htdocs\\DB\\ajax';
//include( $xajax_dir . DIRECTORY_SEPARATOR . 'drawTableSqlString.php' );
//include ('drawTableSqlString.php');
//include_path=".;c:\php\includes"
//http://www.php.net/manual/en/ini.core.php#ini.include-path
//set_include_path(".;c:\xampp\htdocs\DB\ajax");
//include ('drawTableSqlString.php');
//echo get_include_path();
Any help would be really apreciated.
EDIT:
Since I changed some parts of the php.ini I get an error when staring XAMPP saying:
Fatal Error: Directive 'register_globals' is no longer available in
PHP
I am trying to use dompdf to save a form to an easily-readable .pdf file, and my processing script is below. I am receiving the error Warning: file_put_contents(/files/grantapps/NAME0.pdf) [function.file-put-contents]: failed to open stream: No such file or directory in /home/username/public_html/subdir/apps/dompdf/filename.php on line 39. (Line 39 is the final line in my full script.) I don't know how to resolve this issue.
allow_url_fopen is on, and I have tried all kinds of file paths, including the full directory (/home/username/public_html/subdir/files/grantapps/) and what's in the code below, but nothing worked.
require_once("dompdf_config.inc.php");
date_default_timezone_set('America/Detroit');
$html = 'code and whatnot is here';
$name = str_replace(" ", "", $_POST['form2name']);
$i = 0;
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
while(file_exists("files/grantapps/" . $name . $i . ".pdf")) {
$i++;
}
file_put_contents("files/grantapps/" . $name . $i . ".pdf", $dompdf->output());
There is definitly a problem with the destination folder path.
Your above error message says, it wants to put the contents to a file in the directory /files/grantapps/, which would be beyond your vhost, but somewhere in the system (see the leading absolute slash )
You should double check:
Is the directory /home/username/public_html/files/grantapps/ really present.
Contains your loop and your file_put_contents-Statement the absolute path /home/username/public_html/files/grantapps/
I was also stuck on the same kind of problem and I followed the simple steps below.
Just get the exact url of the file to which you want to copy, for example:
http://www.test.com/test.txt (file to copy)
Then pass the exact absolute folder path with filename where you do want to write that file.
If you are on a Windows machine then
d:/xampp/htdocs/upload/test.txt
If you are on a Linux machine then
/var/www/html/upload/test.txt
You can get the document root with the PHP function $_SERVER['DOCUMENT_ROOT'].