关于使用阿里云主机报错“realpath() [function.realpath]: open_basedir restriction in effect”的解决办法
更新:2018-08-16 10:11:02
人气:4432
来源:本站整理
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); } } } }
只需要将函数里的程序代码替换一下即可,函数名不用动。替换后问题解决。
推荐的文章
随手记
- ● blob:http地址的原理及生成方法
- ● 华视CVR100系统身份证读卡器web驱动安装不识别解决办法
- ● web应用采用webcam实现拍照上传的PHP示例及参数说明
- ● PHP实现直播推流功能
- ● win10开机后屏幕黑屏只有鼠标但能启动任务管理器
- ● base64.js文件下载及使用方法说明
- ● windows利用bat微信双开、多开
- ● 百度API提交推送报{"error":401,"message":"tokenisnotvalid"}什么原因
- ● 如果在调用创建群接口时没有保存OpenConversationId,可以通过调用本接口通过chatId获取OpenConversationId
- ● Windows中使用BAT文件设置指定IP地址或自动获取IP
PHP经验分享
- ● MySQLSUM在没有符合查询条件时返回结果为空的处理办法
- ● 如何开启PHP8的JIT提升运行速度
- ● 钉钉API接口-用PHP+Curl实现获取用户信息
- ● 钉钉API接口-用PHP+Curl实现获取应用Access_Token
- ● 在PHP中使用CURL,“撩”服务器只需几行——phpcurl详细解析和常见大坑
- ● MySQLInnodb并发涉及参数说明
- ● mysql参数调优之innodb_thread_concurrency、innodb_concurrency_tickets合理的使用cpu性能
- ● PHP用fsockopen检测指定IP端口是否开启可用
- ● PHP用socket检测服务器IP端口是否开放?代码示例
- ● GatewayWorker报错:Waring:Events::onMessageisnotcallable