Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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 codeIgniter-如何从模型访问文本文件_Php_Codeigniter - Fatal编程技术网

Php codeIgniter-如何从模型访问文本文件

Php codeIgniter-如何从模型访问文本文件,php,codeigniter,Php,Codeigniter,我正在尝试从codeIgniter中的模型访问mime.types文件 function get_mime_type($filename, $mimePath = '../../assets'){ $fileext = substr(strrchr($filename, '.'), 1); if (empty($fileext)) return (false); $regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($

我正在尝试从codeIgniter中的模型访问mime.types文件

function get_mime_type($filename, $mimePath = '../../assets'){ 
        $fileext = substr(strrchr($filename, '.'), 1); 
        if (empty($fileext)) return (false); 
        $regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($fileext\s)/i"; 
        $lines = file("$mimePath/mime.types"); 
        foreach($lines as $line){ 
            if (substr($line, 0, 1) == '#') continue; // skip comments 
            $line = rtrim($line) . " "; 
            if (!preg_match($regex, $line, $matches)) continue; // no match to the extension 
                return ($matches[1]); 
        } 
        return (false); // no match at all 
    } 
当我调用它时,我已经尝试了以下方法:

$this->get_mime_type($filename, $mimePath = '../../assets');

$this->get_mime_type($filename, $mimePath = '/zenoir/assets');

$this->get_mime_type($filename, $mimePath = 'http://localhost:8080/zenoir/assets/mime.types');
但是没有运气。mime.types文件位于assets文件夹中,模型为inzenoir/application/models

错误是:

遇到一个PHP错误

严重性:警告

消息:文件(../../assets/mime.types)[function.file]:无法打开流:没有这样的文件或目录

文件名:models/files.php


行号:46

为什么mime类型会给您带来这么多麻烦,请改用


代码的问题是路径问题。使用
BASEPATH
常量,然后从那里开始遍历。您将忽略所有这些类型的路径问题。

如何从基本路径进行遍历?@user225269,如果您使用的是指向
/system/
目录的CI 2
基本路径
链接。只需执行
BASEPATH。“../assets”
作为您案例的示例。
echo mime_content_type($mimePath.$filename);