解析php file_exists无效的解决办法
方法1 :据官方手册上描述若php教程的safe mode相关的设置过于苛刻,就会出现这样的情形:尽管文件真实存在也被误报,认为文件不存在。
由于服务器端的php.ini我们无法操纵,当用ini_set()也关闭不了safe mode模式,我们只有退而求其次,找一个更可靠、安全的检测方法来检测文件是否存在。我们可以借助 $_server['document_root'] 来加以实现。$_server['document_root'] 返回的是网站的根目录,该目录的最后一个子目录不包含目录标志符号“/”,如:
d:/www/htdocs
有了根目录,再加上需要检测的文件的路径,我们将得到一个绝对的路径,php就可以顺利使用file_exists()函数对之进行检测。上述代码我们只需要更改第一行为(注意,我们在config.php之前加上了符号“/”):
$file=$_server['document_root']."/config.php";
如此,代码的执行就很可信,不会出现预期以外的结果。
以上方法同样适用于目录(is_dir())或文件(is_file())的相关检测函数,能够检测出被安全保护的目录或文件是否存在。
最后顺便提一下:这类被php特殊设置所保护的文件在引用(include和require)时不必加上$_server['document_root']路径,因为,根据php说明文档,它们是允许引用的。
方法2:本人的情况是因为文件在windows和linux之间来回的移动。造成linux下文件和目录的访问权限被改变,导致出文件除拥有者外其他均无访问权限。使用chmod -r 755 xxx/* 解决了问题。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor