我有一个功能,检查文件夹是否可写。但是当我尝试像这样使用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访问文件。
如果我删除或制作挂载检查文件,则触摸命令始终返回true。
任何人都知道为什么?
我正在使用:
PHP 5.3.3-7 +使用Suhosin-Patch(cli)挤压19(内置:2014年2月17日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
与SektionEins GmbH的Suhosin v0.9.32.1,Copyright(c)2007-2010OS:
经销商ID:Debian
描述:Debian GNU / Linux 6.0.3(挤压)
发布:6.0.3
代号:挤压
答案 0 :(得分:0)
touch()用于设置文件的访问和修改时间 如果该文件不存在,则将创建该文件。
也许您可以像这样使用file_exists:
$filename = $storageDir . DIRECTORY_SEPARATOR . $mountCheckFile;
if (!file_exists($filename))
return false;
return touch($filename);