Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php JpGraph无法读取字体_Php_Fonts_Truetype_File Exists_Jpgraph - Fatal编程技术网

Php JpGraph无法读取字体

Php JpGraph无法读取字体,php,fonts,truetype,file-exists,jpgraph,Php,Fonts,Truetype,File Exists,Jpgraph,通常我对调试问题很在行,这个问题似乎一直困扰着我。我已经在/usr/share/php/JpGraph/上安装了JpGraph库,并使它可以用于基本图形。我遇到的问题是无法读取我们的/usr/share/fonts/truetype/字体。我在那里安装了arial.ttf,所有者和组设置为root,chmod设置为644,但仍无法读取 这将显示服务器上的文件: root@CBC-SVR-01:/usr/share/fonts/truetype# ls arialbd.ttf cour.ttf

通常我对调试问题很在行,这个问题似乎一直困扰着我。我已经在/usr/share/php/JpGraph/上安装了JpGraph库,并使它可以用于基本图形。我遇到的问题是无法读取我们的
/usr/share/fonts/truetype/
字体。我在那里安装了arial.ttf,所有者和组设置为root,chmod设置为644,但仍无法读取

这将显示服务器上的文件:

root@CBC-SVR-01:/usr/share/fonts/truetype# ls
arialbd.ttf  cour.ttf                    gentium-basic  verdanab.ttf
ariali.ttf   DejaVuSans-BoldOblique.ttf  liberation     verdanai.ttf
arial.ttf    DejaVuSans-Bold.ttf         openoffice     verdana.ttf
comic.ttf    DejaVuSans-Oblique.ttf      timesbd.ttf
courbd.ttf   DejaVuSans.ttf              times.ttf
couri.ttf    gentium                     ttf-dejavu
以下是文件权限:

root@CBC-SVR-01:/usr/share/fonts/truetype# ls -l
total 5108
-rw-r--r-- 1 root root 284560 Jan 20 13:27 arialbd.ttf
-rw-r--r-- 1 root root 207808 Jan 20 13:27 ariali.ttf
-rw-r--r-- 1 root root 296712 Jan 20 13:27 arial.ttf
-rw-r--r-- 1 root root 126364 Jan 20 13:38 comic.ttf
-rw-r--r-- 1 root root 312920 Jan 20 13:31 courbd.ttf
-rw-r--r-- 1 root root  60856 Jan 20 13:35 couri.ttf
-rw-r--r-- 1 root root 303296 Jan 21 17:27 cour.ttf
-rw-r--r-- 1 root root 574636 Sep 29  2010 DejaVuSans-BoldOblique.ttf
-rw-r--r-- 1 root root 634184 Sep 29  2010 DejaVuSans-Bold.ttf
-rw-r--r-- 1 root root 574456 Sep 29  2010 DejaVuSans-Oblique.ttf
-rw-r--r-- 1 root root 683528 Sep 29  2010 DejaVuSans.ttf
drwxr-xr-x 2 root root   4096 Apr 17 16:11 gentium
drwxr-xr-x 2 root root   4096 Apr 17 16:11 gentium-basic
drwxr-xr-x 2 root root   4096 Apr 17 16:11 liberation
drwxr-xr-x 2 root root   4096 Apr 17 16:11 openoffice
-rw-r--r-- 1 root root 334944 Jan 20 13:33 timesbd.ttf
-rw-r--r-- 1 root root 347988 Jan 20 13:37 times.ttf
drwxr-xr-x 2 root root   4096 Apr 17 16:11 ttf-dejavu
-rw-r--r-- 1 root root 137616 Jan 20 13:31 verdanab.ttf
-rw-r--r-- 1 root root 155076 Jan 20 13:47 verdanai.ttf
-rw-r--r-- 1 root root 149752 Jan 20 13:32 verdana.ttf
这是字体目录权限

root@CBC-SVR-01:/usr/share/fonts# ls -l
total 12
drwxr-xr-x 4 root root 4096 Nov 12 22:44 cmap
drwxr-xr-x 7 root root 4096 Apr 17 16:11 truetype
drwxr-xr-x 3 root root 4096 Nov 12 22:44 type1
但问题是PHP和JpGraph无法读取字体文件

如果我使用root用户从命令行运行以下脚本,它将显示
bool(true)
,但是,如果通过web浏览到同一脚本,它将显示
bool(false)


以下是JpGraph的配置文件:

<?php
//=======================================================================
// File:        JPG-CONFIG.INC
// Description: Configuration file for JpGraph library
// Created:     2004-03-27
// Ver:         $Id: jpg-config.inc.php 1871 2009-09-29 05:56:39Z ljp $
//
// Copyright (c) Asial Corporation. All rights reserved.
//========================================================================


//------------------------------------------------------------------------
// Directories for cache and font directory.
//
// CACHE_DIR:
// The full absolute name of the directory to be used to store the
// cached image files. This directory will not be used if the USE_CACHE
// define (further down) is false. If you enable the cache please note that
// this directory MUST be readable and writable for the process running PHP.
// Must end with '/'
//
// TTF_DIR:
// Directory where TTF fonts can be found. Must end with '/'
//
// The default values used if these defines are left commented out are:
//
// UNIX:
//   CACHE_DIR /tmp/jpgraph_cache/
//   TTF_DIR   /usr/share/fonts/truetype/
//   MBTTF_DIR /usr/share/fonts/truetype/
//
// WINDOWS:
//   CACHE_DIR $SERVER_TEMP/jpgraph_cache/
//   TTF_DIR   $SERVER_SYSTEMROOT/fonts/
//   MBTTF_DIR $SERVER_SYSTEMROOT/fonts/
//
//------------------------------------------------------------------------
//define('CACHE_DIR','cache/');
define('TTF_DIR','/usr/share/fonts/truetype/');
// define('MBTTF_DIR','/usr/share/fonts/truetype/');

//-------------------------------------------------------------------------
// Cache directory specification for use with CSIM graphs that are
// using the cache.
// The directory must be the filesysystem name as seen by PHP
// and the 'http' version must be the same directory but as
// seen by the HTTP server relative to the 'htdocs' ddirectory.
// If a relative path is specified it is taken to be relative from where
// the image script is executed.
// Note: The default setting is to create a subdirectory in the
// directory from where the image script is executed and store all files
// there. As ususal this directory must be writeable by the PHP process.
define('CSIMCACHE_DIR','csimcache/');
define('CSIMCACHE_HTTP_DIR','csimcache/');

//------------------------------------------------------------------------
// Various JpGraph Settings. Adjust accordingly to your
// preferences. Note that cache functionality is turned off by
// default (Enable by setting USE_CACHE to true)
//------------------------------------------------------------------------

// Deafult locale for error messages.
// This defaults to English = 'en'
define('DEFAULT_ERR_LOCALE','en');

// Deafult graphic format set to 'auto' which will automatically
// choose the best available format in the order png,gif,jpeg
// (The supported format depends on what your PHP installation supports)
define('DEFAULT_GFORMAT','auto');

// Should the cache be used at all? By setting this to false no
// files will be generated in the cache directory.
// The difference from READ_CACHE being that setting READ_CACHE to
// false will still create the image in the cache directory
// just not use it. By setting USE_CACHE=false no files will even
// be generated in the cache directory.
define('USE_CACHE',false);

// Should we try to find an image in the cache before generating it?
// Set this define to false to bypass the reading of the cache and always
// regenerate the image. Note that even if reading the cache is
// disabled the cached will still be updated with the newly generated
// image. Set also 'USE_CACHE' below.
define('READ_CACHE',true);

// Determine if the error handler should be image based or purely
// text based. Image based makes it easier since the script will
// always return an image even in case of errors.
define('USE_IMAGE_ERROR_HANDLER',true);

// Should the library examine the global php_errmsg string and convert
// any error in it to a graphical representation. This is handy for the
// occasions when, for example, header files cannot be found and this results
// in the graph not being created and just a 'red-cross' image would be seen.
// This should be turned off for a production site.
define('CATCH_PHPERRMSG',true);

// Determine if the library should also setup the default PHP
// error handler to generate a graphic error mesage. This is useful
// during development to be able to see the error message as an image
// instead as a 'red-cross' in a page where an image is expected.
define('INSTALL_PHP_ERR_HANDLER',false);

// Should usage of deprecated functions and parameters give a fatal error?
// (Useful to check if code is future proof.)
define('ERR_DEPRECATED',true);

// The builtin GD function imagettfbbox() fuction which calculates the bounding box for
// text using TTF fonts is buggy. By setting this define to true the library
// uses its own compensation for this bug. However this will give a
// slightly different visual apparance than not using this compensation.
// Enabling this compensation will in general give text a bit more space to more
// truly reflect the actual bounding box which is a bit larger than what the
// GD function thinks.
define('USE_LIBRARY_IMAGETTFBBOX',true);

//------------------------------------------------------------------------
// The following constants should rarely have to be changed !
//------------------------------------------------------------------------

// What group should the cached file belong to
// (Set to '' will give the default group for the 'PHP-user')
// Please note that the Apache user must be a member of the
// specified group since otherwise it is impossible for Apache
// to set the specified group.
define('CACHE_FILE_GROUP','www');

// What permissions should the cached file have
// (Set to '' will give the default persmissions for the 'PHP-user')
define('CACHE_FILE_MOD',0664);

// Default theme class name
define('DEFAULT_THEME_CLASS', 'UniversalTheme');

define('SUPERSAMPLING', true);
define('SUPERSAMPLING_SCALE', 1);

?>


如果有什么不同的话,我正在运行ispconfig3.0.5.3,经过了大量的测试和反复试验。我最终得到了一个错误代码,它为我指明了正确的方向

Warning: imagettftext(): open_basedir restriction in effect. File(/usr/share/fonts/truetype/arial.ttf) is not within the allowed path(s):
然后我必须读一些书,了解OpenU basedir。现在我知道我必须找到我需要在配置中输入trutype目录的位置,以允许特定站点访问该目录

导航到:ISPConfig-->站点-->[单击域]-->选项-->PHP open_base_dir并将
:/usr/share/font/truetype
添加到已有的内容中。现在JpGraph可以正确读取字体


我希望这将对其他使用ISPConfig和open_basedir配置的用户有所帮助。

只需将arial.ttf字体文件上载到字体文件夹jpgraph/font中即可


就是这样

如果您在共享主机中,您不应该拥有权限,或者字体位于其他路径中。您可以复制项目中的字体并修改目录

在jpgraph.php中:

//
// Setup path for western/latin TTF fonts
//
if (!defined('TTF_DIR')) {
    if (strstr( PHP_OS, 'WIN') ) {
        $sroot = getenv('SystemRoot');
        if( empty($sroot) ) {
            $t = new ErrMsgText();
            $msg = $t->Get(12,$file,$lineno);
            die($msg);
        }
        else {
            define('TTF_DIR', $sroot.'/fonts/');
        }
    } else {
        //define('TTF_DIR','/usr/share/fonts/truetype/');
        **// YOUR FONTS:
        define('TTF_DIR', 'includes/jpgraph/src/fonts/');**
    }
}

我也有同样的问题,但使用了另一种字体。 我所做的是在jpg-config.inc.php中专门定义所需字体(也称为dejavu)的路径,它成功了

我刚刚添加了下一行:

定义('TTF_DIR','/usr/share/fonts/truetype/TTF dejavu/')


希望能有帮助。干杯

我将在2014年4月19日被允许出席明天的会议时接受此答案,除非在此之前还有其他被认为更好的答案。如果您的主机提供商不允许您更改open_basedir设置,这是一个很好的解决方案
//
// Setup path for western/latin TTF fonts
//
if (!defined('TTF_DIR')) {
    if (strstr( PHP_OS, 'WIN') ) {
        $sroot = getenv('SystemRoot');
        if( empty($sroot) ) {
            $t = new ErrMsgText();
            $msg = $t->Get(12,$file,$lineno);
            die($msg);
        }
        else {
            define('TTF_DIR', $sroot.'/fonts/');
        }
    } else {
        //define('TTF_DIR','/usr/share/fonts/truetype/');
        **// YOUR FONTS:
        define('TTF_DIR', 'includes/jpgraph/src/fonts/');**
    }
}