关于使用阿里云主机报错“realpath() [function.realpath]: open_basedir restriction in effect”的解决办法
更新:2018-08-16 10:11:02
人气:5216
来源:本站整理
A+
最近在使用阿里云主机的时候,发现用PHPEXCEL导出数据表时,系统报出以下错误:
Warning: realpath() [function.realpath]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/data/home/byu2599880001/:/usr/home/byu2599880001/:/data/home/tmp/:/usr/home/tmp/:/var/www/disablesite/) in /data/home/byu2599880001/htdocs/peixun/PHPExcel/Shared/File.php on line 136
在网上查询,有些是让修改PHP.INI文件,但一般用主机类的用户都没有权限进行设置,后来在网上查询,是可以通过修改PHPExcel/Shared/File.php文件进行解决。
查找到以下代码函数function sys_get_temp_dir()
public static function sys_get_temp_dir()
{
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
if (!function_exists('sys_get_temp_dir')) {
if ($temp = getenv('TMP')) {
if (file_exists($temp)) {
return realpath($temp);
}
}
if ($temp = getenv('TEMP')) {
if (file_exists($temp)) {
return realpath($temp);
}
}
if ($temp = getenv('TMPDIR')) {
if (file_exists($temp)) {
return realpath($temp);
}
}
// trick for creating a file in system's temporary dir
// without knowing the path of the system's temporary dir
$temp = tempnam(__FILE__, '');
if (file_exists($temp)) {
unlink($temp);
return realpath(dirname($temp));
}
return null;
}
// use ordinary built-in PHP function
//There should be no problem with the 5.2.4 Suhosin realpath() bug, because this line should only
//be called if we're running 5.2.1 or earlier
return realpath(sys_get_temp_dir());
}将以上代码替换为以下代码:
public static function sys_get_temp_dir()
{
// use upload-directory when defined to make it running on
// environments having very restricted open_basedir configs
if (ini_get('upload_tmp_dir') !== false) {
if ($temp = ini_get('upload_tmp_dir')) {
if (file_exists($temp)) {
return realpath($temp);
}
}
}
// sys_get_temp_dir is only available since PHP 5.2.1
// http://php.net/manual/en/function.sys-get-temp-dir.php#94119
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);
}
}
}
}只需要将函数里的程序代码替换一下即可,函数名不用动。替换后问题解决。
推荐的文章
随手记
- ● 统信UOS系统如何设置指定时间自动重启系统的方法
- ● 自制(IP或域名)可信任的SSL证书,适用360、chrome等浏览器
- ● windows系统下php无法使用curl怎么办?
- ● 绿联UGREENKVM切换器(分屏器)快捷键丢失解决办法
- ● 统信UOS开机指定网址全屏启动自带浏览器以及屏蔽ALT+F4关闭
- ● xshellSSH连接Linux服务器防止超时退出
- ● php8开启OpenSSL扩展库报错disabledinstallext
- ● 统信系统linux安装php时的报错libxml-2.0>=2.7.6
- ● tidb关闭sql_mode=ONLY_FULL_GROUP_BY模式
- ● windows10如何开机自动运行bat文件
PHP经验分享
- ● PHP批量对TCP服务端指定多个IP非阻塞检查在线状态
- ● python实现TCP服务端持续接收关机、重启指令并输出结果【系列三】
- ● PHP给TCP服务端发送指令【系列二】
- ● PHP判断TCP服务端是否在线【系列一】
- ● PHP判断远程文件是否存在
- ● LINUX下用PHP获取CPU型号、内存占用、硬盘占用等信息代码
- ● PHP代码用UDP方式远程唤醒电脑让计算机开机
- ● apache下php生成验证码图片不能显示
- ● PHP使用AES加密解密示例(无偏移)
- ● Pluginmysql_native_passwordreported:''mysql_native_password'isdeprecate问题








