【问题标题】:File does not exits or found文件不存在或找不到
【发布时间】:2016-01-05 02:10:38
【问题描述】:

我正在项目中实施验证码。我正在使用 codeigniter 框架。在 captcha_helper.php 文件中的代码

$use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE;

返回 false。因为file_exists($font_path) 正在返回 false。 我路过

$img_path = '../../captcha/';
        $img_url = base_url() . 'captcha/';
        $font_path = base_url(). 'captcha/font/impact.ttf';

$captch = array(
            'word' => '',
            'img_path' => $img_path,
            'img_url' => $img_url,
            'font_path' => $font_path,
            'img_width' => '200',
            'img_height' => '50',
            'expiration' => '300'
        );
 $cap = create_captcha($captch);

现在,当我回显$font_path并在浏览器中复制并粘贴相同的url时,提示字体文件是下载意味着路径是正确的。那么,为什么 file_exists($font_path) 会返回 false。 我尽力了也弄不明白。请帮助我,如果有任何愚蠢的错误,请原谅我。

【问题讨论】:

    标签: php codeigniter captcha


    【解决方案1】:

    试试:

    $font_path = realpath($image_path . 'font/impact.ttf');
    

    问题在于 base_url() 返回一个 URL,您需要使用完整路径(例如 /home/yoursite/public_html/captcha/font/impact.ttf)查看本地文件系统

    【讨论】:

      【解决方案2】:

      根据PHP manual,file_exists 接受文件名作为其参数:文件或目录的路径,而不是它的 URL。它不使用 HTTP 请求访问文件。我打赌file_exists('/captcha/font/impact.ttf') 会返回 true!

      【讨论】:

        猜你喜欢
        • 2015-12-15
        • 2020-08-17
        • 2012-12-15
        • 2020-10-07
        • 2019-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多