php - PHP 中的 while 和 file_exists

标签 php while-loop header file-exists

我在 php 上有这个代码:

while (!file_exists(test.txt)) sleep(1); //wait for test.txt (in the same path)
header("Location:loading.php"); //proceed with the next page

但是这不起作用。

即使文件正确生成,它也会保持在循环中。

我只希望他找到文件后,继续处理标题,但在此之前不会继续。

谢谢。

最佳答案

您需要将文件名括在引号中,以便 file_exists 函数能够正确读取它。您可能还需要指定文件的完整路径。

尝试这样:

while (!file_exists('/path/to/test.txt')) sleep(1); //wait for test.txt (in the same path)
header("Location:loading.php"); //proceed with the next page

关于php - PHP 中的 while 和 file_exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51310347/

相关文章:

php - 使用 aFetch($sql) 问题用 php 从 mysql db 中获取所有行

php - 检查用户友谊

php - 查找指定日期之前的日期并使用 PHP 和 SQL 插入它们

http - 为 Feature-Policy HTTP header 设置默认值

php - WordPress 无法加载(连接超时)

Python在while循环的条件下为变量赋值

php - if 语句或 while 循环在 php 中对我失败

Java String ReplaceAll 方法对循环有异常影响?

配置单元中的 Json 文件加载跳过第 1 行

C头文件#ifndef#include错误