drfred Posted September 16, 2017 Share Posted September 16, 2017 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? Quote Link to comment https://forums.phpfreaks.com/topic/304997-fopen-error-in-tcpdf/ Share on other sites More sharing options...
Jacques1 Posted September 16, 2017 Share Posted September 16, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/304997-fopen-error-in-tcpdf/#findComment-1551377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.