php - 为什么文件存在时 file_exists() 返回 false?

标签 php google-api xampp

我尝试使用 Google API,但在处理过程中出现错误,提示文件丢失。

在尝试访问退出的文件时,file_exists() 返回 false,不知道我哪里出错了。

注意:它在本地主机中,使用 Xampp。

执行结果: enter image description here

目录图像:enter image description here

文件.php:

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

关于php - 为什么文件存在时 file_exists() 返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48181280/

相关文章:

Laravel 5.6 - session 过期后不会持续存在

php - 如何隐藏实际的下载文件夹位置

php - 根据一条记录列值选择多条记录

python - 如何列出 Google Merchant Center Feed

google-app-engine - OAuth2.0 无效的 redirect_uri 参数值 : Missing scheme

php - 无法让 Xdebug 在 Windows 7 上运行

php - 从 cakephp 中的两级父模型中选择字段

php - 在 php 中回显错误

javascript - 设置 Google Plus 登录按钮类型

mysql - xampp - 从局域网内的另一台本地机器连接到本地数据库