Jump to content

Recommended Posts

I'm trying to access a font file: usr/share/fonts/truetype/verdana.ttf

FontsInaccessible1.png.b671e129825c610fb58fbf59a7118169.png

As you can see the file does exist and owner, group and public have permissions to read it.
It is owned by root not www-data but I can't see how that's a problem if public has read permissions.

My code:
 

if(file_exists("usr/share/fonts/truetype/verdana.ttf"))  echo "file exists<br>";
else echo "file does NOT exist<br>";

$file = file_get_contents("usr/share/fonts/truetype/verdana.ttf");
if($file === false) echo "no file<br>";
else echo $file . "<br>";

returns:
file does NOT exist
no file

How can I make my fonts in usr/share/fonts/truetype/ accessible to PHP?

 

Thanks. I can't believe I didn't see that!

It didn't work though.

So, now my code is:

if(file_exists("/usr/share/fonts/truetype/verdana.ttf"))  echo "file exists<br>";
else echo "file does NOT exist<br>";

$file = file_get_contents("/usr/share/fonts/truetype/verdana.ttf");
if($file === false) echo "no file<br>";
else echo $file . "<br>";

The response is still:
file does NOT exist
no file

Also, when I showed errors none appeared.

Then is it impossible to access folders outside the domain root from the website like /usr/share/ ?

I'm accessing multiple folders in /var/www/ for things like PHPWord, JpGraph, etc. They're accessible to all the domains I run.
In fact, the app that needs the fonts is JpGraph.

<?php 

echo "Root: {$_SERVER['DOCUMENT_ROOT']}<br>"; 

if(file_exists("/usr/share/fonts/truetype/verdana.ttf"))  echo "file exists<br>";
else echo "file does NOT exist<br>";

$file = file_get_contents("/usr/share/fonts/truetype/verdana.ttf");
if($file === false) echo "no file<br>";
else echo $file . "<br>";

 

Are you serving this domain yourself on your own box?  Or is it shared hosting from somebody else?  If it is shared then you only have the part of the box then begins with the first two parts of that 'root' path, I think.  My root has 3 folders of which the lowest one is the web root folder.  I can see one folder above that where I store things like my php files so they are not available using html.  Your php can probably only see /var/www

Also, take a look at your PHP error logs, in case there's anything in there that might be relevant to this issue...

And by the way, even if this isn't shared hosting and you own the box, if you need the Verdana font then just bundle it into your application's codebase. Far more reliable than making sure you have fonts installed on what should be a headless box.

It's my box. It's a standard debian apache 2 installation.
All the sites are in /var/www/

Where are the PHP error logs?

What does "bundle it into your application's codebase" mean? Multiple sites; multiple PHP apps will need access to the fonts.

 

Move the fonts folder to something in or below /var/www such as /var/www/fonts  That way all of your apps should see them no matter which domain they are in.   Of course I have no experience in running apps so I may be wrong but that would make sense to me.

OK, I moved the fonts to /var/www/fonts/truetype and set ownership & group to www-data.

The permissions look right. JpGraph seems to be happy now.
Funny though, the JpGraph default path was /usr/share/fonts/truetype which is what sent me down that trail.

I just didn't realize that you can't access any folder on the server from a PHP website.

It's fixed now. Thanks.

Just now, SLSCoder said:

I just didn't realize that you can't access any folder on the server from a PHP website.

You can, but it depends on configuration. Or a lack of, such as for the open_basedir PHP setting that would restrict your code from doing anything outside of a specific set of directories if it had been set.

I don't know where your PHP logs are. Start looking at /var/log.

Because you put your root in a different branch of the file system.  I think the sample you used was just that - a sample.  Your user (as you now see) had to be "/var/www".  When you setup your tree on day 1 if you had used 'usr' things would have worked.

  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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