关于使用阿里云主机报错“realpath() [function.realpath]: open_basedir restriction in effect”的解决办法
更新:2018-08-16 10:11:02
人气:4702
来源:本站整理
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开机指定网址全屏启动自带浏览器以及屏蔽ALT+F4关闭
- ● xshellSSH连接Linux服务器防止超时退出
- ● php8开启OpenSSL扩展库报错disabledinstallext
- ● 统信系统linux安装php时的报错libxml-2.0>=2.7.6
- ● tidb关闭sql_mode=ONLY_FULL_GROUP_BY模式
- ● windows10如何开机自动运行bat文件
- ● Win10Mysql8初始密码丢失,初始化又不显示密码
- ● UOS系统关闭防火墙或者放行tcp80端口
- ● 统信系统UOS纯命令行与图形模式界面桌面切换方法
- ● javascript(js)的小数点乘法除法问题详解
PHP经验分享
- ● PHP代码用UDP方式远程唤醒电脑让计算机开机
- ● apache下php生成验证码图片不能显示
- ● PHP使用AES加密解密示例(无偏移)
- ● Pluginmysql_native_passwordreported:''mysql_native_password'isdeprecate问题
- ● PHP实现计算CRC-16/MODBUS校验位
- ● MySQLSUM在没有符合查询条件时返回结果为空的处理办法
- ● 如何开启PHP8的JIT提升运行速度
- ● 钉钉API接口-用PHP+Curl实现获取用户信息
- ● 钉钉API接口-用PHP+Curl实现获取应用Access_Token
- ● 在PHP中使用CURL,“撩”服务器只需几行——phpcurl详细解析和常见大坑