只有变量可以通过引用错误传递 [英] Only Variables can be passed by reference error
问题描述
脚本 '/usr/local/apache2/htdocs/read.php' 第 197 行发生错误:只应通过引用传递变量(第 196 行是 $ext = strtolower(array_pop(explode('.',$filename)));
)
An error occurred in script '/usr/local/apache2/htdocs/read.php' on line 197: Only variables should be passed by reference (line 196 is
$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,虽然我遇到了一个我似乎无法弄清楚的致命错误.有没有人有这方面的经验并指出或指出正确的方向?
I'm using this little script from http://php.net/manual/en/function.mime-content-type.php, though I'm getting a fatal error I can't seem to figure out. Does anyone that has experience with this and shed some light or point me in the right direction?
推荐答案
在传递之前,你需要把explode()的结果变成一个变量
You need to make the result of explode() a variable before you pass it on
$var = explode('.',$filename);
$ext = strtolower(array_pop($var));
这篇关于只有变量可以通过引用错误传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!