php realpath,file_exists文件存在却返回false解决办法
昨天下载的php网站配招运行环境进行安装时(系统环境:window2003+IIS6+FastCGI+PHP5.3.4),一直无法正常运行,一直提示程序已经安装,要删除lock文件。查看网站根目录下的index.php代码,里面有如下代码
if(!file_exists('install/lock')){ //下面2句自己加的,输出路径 echo '-'.realpath('install/lock').'-'.'-<br/>'; echo '-'.realpath('index.php').'-<br/>'; // header('Location:install/index.php'); exit(); }
结果realpath无法获取路径。realpath输出为空,file_exists也返回为false(100%确认install/lock文件存在)。
但是在install目录下index.php文件有下面的语句,确可以执行。。也能获取都路径,上级目录的也没问题。
if (file_exists('lock')){ @header("Content-type: text/html; charset=UTF-8"); echo '-'.realpath('lock').'-<br/>';//路径正确,输出D:\phpwebs\xxxx\install\lock
echo '-'.realpath('../index.php').'-<br/>';//路径正确,输出D:\phpwebs\xxxx\index.php
echo "系统已经安装过了,如果要重新安装,那么请删除install目录下的lock文件"; exit; }
xxx为网站根目录。
经过排查后发现原来是运行php网站的用户没有对网站根目录的父目录(D:\phpwebs
这个目录
)读取权限造成的,加上运行php网站用户对D:\phpwebs的读取权限后程序马上正确执行,根目录下的index.php的file_exists正常获取到文件,返回true,没有执行if(!file_exists('install/lock'))这个判断输出realpath了。
苦逼。。为什么asp.net不需要添加网站根目录的父目录访问权限也正常呢。。
加支付宝好友偷能量挖...
原创文章,转载请注明出处:php realpath,file_exists文件存在却返回false解决办法