新闻中心

PHPCMSV9上传附件错误提示信息为空白

作者 / 无忧主机 时间 2014-03-27 17:54:48

关于phpcmsV9后台上传图片出错的问题,之前无忧主机小编也遇到过类似的,但是这次完全是没有提示的错误,直接弹出一个空白的对话框,如下图所示:   [caption id="attachment_13734" align="alignnone" width="540"]phpcms后台 phpcms后台[/caption] 这种的毫无提示,连报错都让人一头雾水。一开始发现系统在其它服务器上运行ok,以为是这台服务器的问题,所以一直把精力放到服务器的环境配置上了,比如上传大小限制,上传的目录权限,网站文件夹的权限设置。后来发现问题是看到php的错误日志,定位到错误发生在移动临时上传文件到保存目录的地方,路径中多了一条下划线。 然后才找到这段离奇的代码

$temp_filename = $this->getname($fileext);

$savefile = $this->savepath.$temp_filename;

$savefile = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile);

$filepath = preg_replace(new_addslashes("|^".$this->upload_root."|"), "", $savefile);

if(!$this->overwrite && file_exists($savefile)) continue;

$upload_func = $this->upload_func;

if(@$upload_func($file['tmp_name'], $savefile)) {

$this->uploadeds++;

@chmod($savefile, 0644);

@unlink($file['tmp_name']);

$file['name'] = iconv("utf-8",CHARSET,$file['name']);

$uploadedfile = array('filename'=>$file['name'], 'filepath'=>$filepath, 'filesize'=>$file['size'], 'fileext'=>$fileext, 'fn'=>$file['fn']);

$thumb_enable = is_array($thumb_setting) && ($thumb_setting[0] > 0 || $thumb_setting[1] > 0 ) ? 1 : 0;

$image = new image($thumb_enable,$this->siteid);

if($thumb_enable) {

$image->thumb($savefile,'',$thumb_setting[0],$thumb_setting[1]);

}

if($watermark_enable) {

$image->watermark($savefile, $savefile);

}

$aids[] = $this->add($uploadedfile);

}
    这个程序员哥哥的意图是对非法的文件扩展名进行安全过滤,但发生一件很碉堡的事情,就是把整个路径给进行了过滤。 $savefile=preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $savefile); 这段屏蔽代码的意识就是把带有php/jsp/asp......等等字样的路径去除,所以哪位仁兄刚好域名是带PHP ,asp等的,就有可能会出现这个状况的报错,而无忧主机刚好是,所以结果就是域名被屏蔽了,当然图片找不到保存的路径了。 解决办法很简单。注释掉这行或者改成下面的代码 $temp_filename = $this->getname($fileext); $temp_filename = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2", $temp_filename); $savefile = $this->savepath.$temp_filename;   相关文章推荐阅读: 解决PHPCMSV9网站更换域名后无法上传图片 PHPCMS V9.42版本上传图片出现UNDEFINED解决办法 PHPCMS后台上传图片成功但实际并未上传的解决办法  

本文地址:https://www.51php.com/phpcms/13733.html

1
1
1
1
1
1
1

客户服务热线

0791-8623-3537

在线客服