gpt4 book ai didi

PhP 触摸不存在的文件返回 true

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:30:56 24 4
gpt4 key购买 nike

我有一个功能可以检查文件夹是否可写。但是当我尝试像这样在其中使用 php touch 变量时

public function isFileServerMounted()
{
$config = $this->getServiceLocator()->get('config');

$storageDir = $config['xxx']['xxx']['xxx'];
$mountCheckFile = $config['xxx']['xxx']['xxxx'];

// we are using a simple file check as indication if we are mounted
return touch($storageDir . DIRECTORY_SEPARATOR . $mountCheckFile);
}

无论我正在检查的文件是否存在,该函数始终返回 true。我检查了路径,它们是正确的,我可以通过 nano over schiell 访问文件。

触摸命令总是返回真,不管我是删除还是创建挂载检查文件。

有人知道为什么吗?

我正在使用:

带有 Suhosin-Patch (cli) 的 PHP 5.3.3-7+squeeze19(构建时间:2014 年 2 月 17 日 10:10:23)

版权所有 (c) 1997-2009 The PHP Group

Zend Engine v2.3.0,版权所有 (c) 1998-2010 Zend Technologies

使用 Xdebug v2.2.5,版权所有 (c) 2002-2014,作者 Derick Rethans

使用 Suhosin v0.9.32.1,版权所有 (c) 2007-2010,SektionEins GmbH

操作系统:

发行商 ID:Debian

说明:Debian GNU/Linux 6.0.3(挤压)

版本:6.0.3

代号:挤压

最佳答案

touch()是设置文件的访问和修改时间。
如果该文件不存在,将创建它。

也许你可以使用file_exists像这样:

$filename = $storageDir . DIRECTORY_SEPARATOR . $mountCheckFile;

if (!file_exists($filename))
return false;

return touch($filename);

关于PhP 触摸不存在的文件返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27418291/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com