Jump to content

fopen error in tcpdf


Recommended Posts

I am using the TCPDF library and have run into an error

	public static function fopenLocal($filename, $mode) {
		if (strpos($filename, '://') === false) {
			$filename = 'file://'.$filename;
		} elseif (stream_is_local($filename) !== true) {
			return false;
		return fopen($filename, $mode);

this turns my local filename: docs/filename.pdf into file://docs/filename.pdf


in the documentation for stream_is_local there is the comment:


It appears to return incorrectly for 'file://' wrapper which I would consider to be local.


$file1 = '/somefile.jpg';
$file2 = 'file://shouldbelocal.jpg';
$file3 = 'http://someotherfile.jpg';

$local = stream_is_local($file1);
$shouldbelocal = stream_is_local($file2);
$remote = stream_is_local($file3);
var_dump($local, $shouldbelocal, $remote);


My code is getting past the stream_is_local line, so I guess it is returning true there, but it dies on the fopen line with the error:


fopen(file://docs/filename.pdf): failed to open stream: no suitable wrapper could be found in /Applications/mampstack-7.0.23-0/apache2/htdocs/include/tcpdf_static.php on line 1854


I have checked the php.ini and the line allow_url_fopen=On



Any ideas?


Link to comment
Share on other sites

You need to stop using relative paths all over the place. Not only is this the reason for this particular error. It's also unreliable, because any change of the internal architecture can break all paths at once.


Use absolute paths. Set up a configuration parameter which says where the documents are located. Then append the filename to get a full file path which is completely independent from the location of your script.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.