Jump to content

fopen error in tcpdf


drfred

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.

CODE:

$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);

RESULT:
bool(true)
bool(false)
bool(false)

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.