Php 为什么文件存在时,file_exists()返回false?

Php 为什么文件存在时,file_exists()返回false?,php,google-api,xampp,Php,Google Api,Xampp,我试图使用谷歌API,在这个过程中,我得到了一个错误,说文件丢失了 尝试访问退出的文件时,file\u exists()返回false,不知道哪里出错 注意:它位于本地主机中,使用Xampp 执行结果: 目录的图像: File.php: <?php clearstatcache(); $dir= __DIR__."\client_secret.json"; if (file_exists($dir)){ echo "exists"; } else { echo "doesn't exis

我试图使用谷歌API,在这个过程中,我得到了一个错误,说文件丢失了

尝试访问退出的文件时,
file\u exists()
返回false,不知道哪里出错

注意:它位于本地主机中,使用Xampp

执行结果:

目录的图像:

File.php:

<?php
clearstatcache();
$dir= __DIR__."\client_secret.json";
if (file_exists($dir)){
echo "exists";
} else {
echo "doesn't exist at ".$dir;
}
?>

因为File.php和client_secret.json位于同一个文件中,所以它可以工作。
试试这个


由于
client\u secret.json
文件与
file.php
路径相同,您可以直接执行以下操作

if(file_exists("client_secret.json")){ //file name without whole path
        echo "Exists";
}else{
    echo "Not Found!";
}

file.php路径在哪里?
\uuuuu DIR\uuuuu
将找到file.php目录,因此您可以回显
$DIR
值,然后检查路径是否正确?

从dos对该文件夹进行DIR,并检查您的文件是否未命名

client_secret.json.json

Windows文件资源管理器显示不带扩展名的文件名。您的文件名是client_secret.json,扩展名为.json

<?php
clearstatcache();
$dir= __DIR__."\client_secret.json.json";
if (file_exists($dir)){
echo "exists";
} else {
echo "doesn't exist at ".$dir;
}
?>

File.php的位置我真的不确定这是否可行,但您是否尝试将“\”更改为“/”。按照。您确定在请求文件时设置了正确的路径吗?请确保文件系统上的文件名中没有前导或尾随空格,即“client_secret.json”。@YogeshPaliyal它与client_secret.json位于同一位置。我尝试了“/”,没有更改。它与client_secret.php位于同一目录中。我试过了,路径看起来是正确的,但它仍然说,它不存在。
<?php
clearstatcache();
$dir= __DIR__."\client_secret.json.json";
if (file_exists($dir)){
echo "exists";
} else {
echo "doesn't exist at ".$dir;
}
?>