When using PHPExcel to export execl, I found that there was no problem locally, but when I transferred the website to the rented server, an error was reported. The details are as follows:
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方法的最后一行,查阅网上的方法直接把该方法给替换掉就好了。
The code is as follows:
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); } } }
}
The above introduces the solution to the open_basedir restriction in effect in PHPExcel, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.