2
Contributors
1
Reply
5
Views
2 Years
Discussion Span
Last Post by cereal
0

Hi,

not tested, but according to the library, dompdf works in a chroot so it will not consider files outside of his path, this is defined here:

/**
 * ==== IMPORTANT ====
 *
 * dompdf's "chroot": Prevents dompdf from accessing
 * system files or other files on the webserver.
 * All local files opened by dompdf must be in a subdirectory
 * of this directory.
 * DO NOT set it to '/' since this could allow an attacker
 * to use dompdf to read any files on the server. This
 * should be an absolute path.
 * This is only checked on command line call by dompdf.php,
 * but not by direct class use like:
 * $dompdf = new DOMPDF();
 * $dompdf->load_html($htmldata);
 * $dompdf->render();
 * $pdfdata = $dompdf->output();
 */
def("DOMPDF_CHROOT", realpath(DOMPDF_DIR));

To solve you can move the images to the dompdf root, or to the temp directory, which is defined here:

def("DOMPDF_TEMP_DIR", sys_get_temp_dir());

You can edit the dompdf_config.custom.inc.php file and set your own temp directory, just uncomment the following line:

//define("DOMPDF_TEMP_DIR", "/tmp");

And set an absolute path, for example:

define("DOMPDF_TEMP_DIR", $_SERVER["DOCUMENT_ROOT"]."/images/");

Another solution is to set DOMPDF_ENABLE_REMOTE to TRUE, by default is not active:

def("DOMPDF_ENABLE_REMOTE", false);

With this enabled you can use remote files, so you just need to use absolute links to define the image resource, in practice:

<img src="http://www.mywebsite.tld/images/photo001.jpg" />

Instead of simply:

<img src="/images/photo001.jpg" />

If you still do not solve the problem, share your code and your dompdf configuration.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.