PHPExcel中open_basedir restriction in effect的解决方法

用PHPExcel做导出execl的时候发现在本地没有问题,但是把网站传到租用的服务器的时候就报错,具体如下:

Warning: realpath() [function.realpath]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/data/home:/usr/home:/data/home/tmp:/usr/home/tmp:/var/www/disablesite) in /data/home/【服务器名称】/htdocs/【项目地址】/Classes/PHPExcel/Shared/File.php on line 136  
  
  
  
找到对应的File.php的136行,只是sys_get_temp_dir方法的最后一行,查阅网上的方法直接把该方法给替换掉就好了。  

代码如下: 

public static function sys_get_temp_dir()
{
if
(ini_get('upload_tmp_dir')!==false) { if($temp = ini_get('upload_tmp_dir')) { if (file_exists($temp)) { return realpath($temp); } } } if ( !function_exists('sys_get_temp_dir')) { if ($temp = getenv('TMP')) { if (file_exists($temp)) { return realpath($temp); } if (($temp!='') && file_exists($temp)) { return realpath($temp); } } if ($temp = getenv('TEMP')) { if (file_exists($temp)) { return realpath($temp); } } }
}
原文地址:https://www.cnblogs.com/zhenghongxin/p/5320731.html