douguanya4248 2014-12-11 08:25
浏览 54
已采纳

对非现有文件的PhP触摸返回true

i have a function wich makes a check if a folder is writable. but when i try to use the php touch variable in it like this

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);
}

The function always returns true, regardles if the file i am checking is there or not. i checked the paths and they are correct and i can acess the file via nano over schiell.

The touch comand always returns true, regardles if i delete or make the mount check file.

Anyone has any idea why?

I am using:

PHP 5.3.3-7+squeeze19 with Suhosin-Patch (cli) (built: Feb 17 2014 10:10:23)

Copyright (c) 1997-2009 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

OS:

Distributor ID: Debian

Description: Debian GNU/Linux 6.0.3 (squeeze)

Release: 6.0.3

Codename: squeeze

  • 写回答

1条回答 默认 最新

  • donglulong0877 2014-12-11 08:44
    关注

    touch() is to sets access and modification time of file.
    If the file does not exist, it will be created.

    Maybe you can use file_exists like this:

    $filename = $storageDir . DIRECTORY_SEPARATOR . $mountCheckFile;
    
    if (!file_exists($filename))
        return false;
    
    return touch($filename);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示