Fwd: Re: [PHP] Unable to load a file

Re-transmitted as the original never turned up on the list. My apologies if I just missed the
distribution.

John

OK, I solved this one. When fpdf was installed some of its subdirectories had the wrong permissions
so non-root tasks could not descend them. (rw- should have been r-x) Since the command line job was
run from cron it was running as root so didn't encounter this problem. httpd was run as user apache
so couldn't read the font files.

Sorry for the noise and thanks to Janis Elmeris for trying to assist. Much appreciated.

John

On Thu, 2025-01-16 at 19:30 -0500, John Iliffe wrote:

Re-transmitted as the original never turned up on the list. My apologies if I just missed the
distribution.

John

-------- Forwarded Message --------
From: John Iliffe <john.iliffe@iliffe.ca>
Reply-To: john.iliffe@iliffe.ca
To: Jānis Elmeris <janis.elmeris@lv.lv>
Subject: Re: [PHP] Unable to load a file
Date: 2025-01-16 11:46:28 AM

OK, tried that, thanks for the suggestion. Turns out it is a permission error on the font file:
-----
[16-Jan-2025 11:30:35 America/Toronto] PHP Warning: file_get_contents(/usr/fpdf186/font/garamond-
pro.php): Failed to open stream: Permission denied in /usr/fpdf186/fpdf.php on line 1136
[16-Jan-2025 11:30:35 America/Toronto] Array
(
[$path] => /usr/fpdf186/font/garamond-pro.php
[content] =>
)
-----
but selinux is in permissive mode and the file permissions are:
(httpd is running as user 'apache' which is essentially an unprivileged user)

-rwxr-xr-x. 1 root root 3738 Jan 2 22:04 /usr/fpdf186/font/garamond-pro.php

so readable by anybody. The directory permissions are:

drw-rw-rw-. 2 root root 4096 Jan 2 22:04 .

so nothing blocking decent to the file. Also, have to keep in mind that this works from the
command
prompt.

This system (Rocky 9.5) does not use ACL's either so not that. Anything I missed? It still looks
to me like PHP and not an fpdf problem.

On Thu, 2025-01-16 at 09:51 +0000, Jānis Elmeris wrote:
>
> You may try adding debugging: in fpdf.php on line 1136, at the beginning of the function:
>
>
> error_log(print_r(['$path' => $path, 'content' => file_get_contents($path),], true));
>
>
> And see whether you get the expected output in the log.
> Compare what you get when you run it with CLI and with the webserver.
>
>
> Also, I see there is a difference between "Garamond Pro-Regular.php" and "garamond-pro.php" in
> your examples. I guess it is because you collected the examples from different times when you
> were
> experimenting with the code?
>
>
> Regards,
> Janis
------snip-----

Thank you for the useful feedback!

Regards,
Janis

···

No: John Iliffe john.iliffe@iliffe.ca
Nosūtīts: piektdiena, 2025. gada 17. janvāris 20:27
Kam: PHP Help php-general@lists.php.net
Tēma: Re: Fwd: Re: [PHP] Unable to load a file

OK, I solved this one. When fpdf was installed some of its subdirectories had the wrong permissions
so non-root tasks could not descend them. (rw- should have been r-x) Since the command line job was
run from cron it was running as root so didn’t encounter this problem. httpd was run as user apache
so couldn’t read the font files.

Sorry for the noise and thanks to Janis Elmeris for trying to assist. Much appreciated.

John

On Thu, 2025-01-16 at 19:30 -0500, John Iliffe wrote:

Re-transmitted as the original never turned up on the list. My apologies if I just missed the
distribution.

John

-------- Forwarded Message --------
From: John Iliffe john.iliffe@iliffe.ca
Reply-To: john.iliffe@iliffe.ca
To: Jānis Elmeris janis.elmeris@lv.lv
Subject: Re: [PHP] Unable to load a file
Date: 2025-01-16 11:46:28 AM

OK, tried that, thanks for the suggestion. Turns out it is a permission error on the font file:

[16-Jan-2025 11:30:35 America/Toronto] PHP Warning: file_get_contents(/usr/fpdf186/font/garamond-
pro.php): Failed to open stream: Permission denied in /usr/fpdf186/fpdf.php on line 1136
[16-Jan-2025 11:30:35 America/Toronto] Array
(
[$path] => /usr/fpdf186/font/garamond-pro.php
[content] =>
)

but selinux is in permissive mode and the file permissions are:
(httpd is running as user ‘apache’ which is essentially an unprivileged user)

-rwxr-xr-x. 1 root root 3738 Jan 2 22:04 /usr/fpdf186/font/garamond-pro.php

so readable by anybody. The directory permissions are:

drw-rw-rw-. 2 root root 4096 Jan 2 22:04 .

so nothing blocking decent to the file. Also, have to keep in mind that this works from the
command
prompt.

This system (Rocky 9.5) does not use ACL’s either so not that. Anything I missed? It still looks
to me like PHP and not an fpdf problem.

On Thu, 2025-01-16 at 09:51 +0000, Jānis Elmeris wrote:

You may try adding debugging: in fpdf.php on line 1136, at the beginning of the function:

error_log(print_r([‘$path’ => $path, ‘content’ => file_get_contents($path),], true));

And see whether you get the expected output in the log.
Compare what you get when you run it with CLI and with the webserver.

Also, I see there is a difference between “Garamond Pro-Regular.php” and “garamond-pro.php” in
your examples. I guess it is because you collected the examples from different times when you
were
experimenting with the code?

Regards,
Janis
------snip-----