【问题标题】:Why doesn't file_exists() work?为什么 file_exists() 不起作用?
【发布时间】:2010-10-31 04:32:55
【问题描述】:

这是我的 PHP 代码:

[root@file htdocs]# vi test.php
<?php

var_dump(file_exists('/usr/local/apache2/resumes/28/"Chapel Hill"/franky_li/"CV.doc"'));
?>

"test.php" [New] 5L, 100C written
[root@file htdocs]# php test.php 
bool(false)

说文件不存在,但实际上确实存在:

[root@file htdocs]# ls -l /usr/local/apache2/resumes/28/"Chapel Hill"/franky_li/"CV.doc"
-rw-r--r-- 1 daemon root 36864 Oct 17  2008 /usr/local/apache2/resumes/28/Chapel Hill/franky_li/CV.doc
[root@file htdocs]# 

似乎确实是报价问题:

<?php


var_dump(file_exists('/usr/local/apache2/resumes/28/Chapel Hill/franky_li/CV.doc'));
?>
~
~
"test.php" 5L, 96C written
[root@file htdocs]# php test.php 
bool(true)
[root@file htdocs]# 

现在使用以下转换器修复:

preg_replace('/\/([^\/\s]+\s+[^\/]+)(?:\/|$)/','/"${1}"/',$file);

让它在 bash 中工作!

【问题讨论】:

标签: php quotes file-exists


【解决方案1】:

尝试删除双引号,因为它已经被单引号引用了。

【讨论】:

  • 我需要运行 exec(),它运行一个 bash 命令,任何一方都无法以这种方式工作。
  • 在不同位置的不同文件上尝试 file_exists() 以查看它是否有效。如果它确实有效,那么您的问题是无法访问。如果它不起作用,那么问题出在命令上,我们可以从那里开始处理它。告诉我。
  • 好。您的问题现在解决了吗,还是您在使用 exec() 时遇到了问题?
  • 太棒了。如果您有任何问题,请在此处发布。
【解决方案2】:

查看file_exists 的手册。

注意本节:

"对于由于安全模式限制而无法访问的文件,此函数返回 FALSE。但是,如果这些文件位于 safe_mode_include_dir 中,仍然可以包含这些文件。"

我的猜测是您使用的是

【讨论】:

    猜你喜欢
    • 2017-05-14
    • 2017-03-11
    • 2011-11-05
    • 2014-08-05
    • 2015-11-09
    • 2017-03-27
    • 2010-11-20
    • 1970-01-01
    • 2016-09-02
    相关资源
    最近更新 更多