我有一个函数,可以检查文件夹是否可写。 但是当我尝试像这样在其中使用 PHP 触摸变量时
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 而不是 Schiell 访问文件。
触摸通信总是返回 true,如果我删除或制作挂载检查文件。
有人知道为什么吗?
我正在使用:
PHP 5.3.3-7+squeeze19 with Suhosin-Patch (cli) (建成时间: Feb 17 2014 10:10:23)
版权所有 (c) 1997-2009 PHP集团
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);