只有变量可以通过引用传递错误。

9
在脚本'/usr/local/apache2/htdocs/read.php'的第197行发生了错误: 只能传递变量的引用 (第196行是$ext = strtolower(array_pop(explode('.',$filename)));)。
if(!function_exists('mime_content_type')) {

    function mime_content_type($filename) {

        $mime_types = array(

            'txt' => 'text/plain',
            'htm' => 'text/html',
            'html' => 'text/html', //ETC

        );

        $ext = strtolower(array_pop(explode('.',$filename)));
        if (array_key_exists($ext, $mime_types)) {
            return $mime_types[$ext];
        }
        elseif (function_exists('finfo_open')) {
            $finfo = finfo_open(FILEINFO_MIME);
            $mimetype = finfo_file($finfo, $filename);
            finfo_close($finfo);
            return $mimetype;
        }
        else {
            return 'application/octet-stream';
        }
    }
}

我正在使用来自http://php.net/manual/en/function.mime-content-type.php的小脚本,但我遇到了一个致命错误,我似乎无法解决。有没有人有相关经验可以给我指点迷津?
2个回答

11
你需要将explode()的结果赋值给一个变量,然后再将其传递。
$var = explode('.',$filename);
$ext = strtolower(array_pop($var));

@Dendromaniac 如果这个问题和这个解决方案对你不起作用,那么请创建一个新的问题,并附上你的代码,这样其他人可以帮你解决。 - JohnP
我犯了一个错误,正在编辑mime-lib.php的错误副本,我的错。 - Dendromaniac

7
那段代码将explode函数的结果(一个值)传递给array_pop,但是array_pop需要一个数组变量(通过引用),而不是一个值。 (array_pop声明中的&告诉我们它希望接受一个引用。)
您可以通过使用数组变量存储explode的结果,然后将其传递到array_pop来解决此问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接