BCcampus / pressbooks-mpdf

[UNMAINTAINED] open source HTML to PDF conversion
GNU General Public License v2.0
7 stars 7 forks source link

chmod() operation not permitted #19

Closed ghost closed 7 years ago

ghost commented 7 years ago

We are using Pressbooks and the Pressbooks mPDF plugin on a hosting provider that does not allow the use of PHP's chmod() function and has a single dedicated place where plugins can write files to.

Our workaround for this was to comment out the chmod() line in pressbooks-mpdf.php and to symlink the ttfontdata, graph_cache, and tmp directories (in both vendor and symbionts/mpdf) to the directory our hosting provider allows write access to. All of this is to say that it works, but the solution we've implemented isn't ideal because it means we have to hack stuff in your code to make it work, and in the future when this plugin updates, we'll have to reimplement our changes.

My question is, why do the folders listed above need to be writable? What are they used for? Is there a way this plugin can work its magic without requiring write access to any files?

bdolor commented 7 years ago

Hi @monkecheese — thanks for being patient for a response. The quickest explanation I have is that the reason the folders need to be writable is because that's what the documentation states is necessary.

reference: https://mpdf.github.io/installation-setup/installation-v6-x.html

explanation:

mPDF is configured to use [your_path_to_mpdf]/tmp/ as a folder to write temporary files (mainly for images), and [your_path_to_mpdf]/ttfontdata/ as a folder to cache font metrics data. Write permissions should ideally be set on both these folders to allow read/write access for the script.

On the following page it describes two constants _MPDF_TEMP_PATH and _MPDF_TTFONTDATAPATH that can be set to change the location of the temporary files.

https://mpdf.github.io/installation-setup/folders-for-temporary-files.html

It's not clear to me if setting those constants would be a sufficient alternative to the work around that you've already employed or not. If you end up testing it, would you be able to report back? If there's anything that can be modified, let me know.

ghost commented 7 years ago

This is great, thanks @bdolor. When I have a moment to try a few things out, I'll let you know what I find.

Without having taken a dive into the code, my initial thought is that it may be possible to allow users of the plugin to set their own write path for ttfontdata, tmp, and graph_cache by setting those constants you mentioned with a filter hook.