我在 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/