1

Here is my PHP code:

[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)

which says the file doesn't exists,but in fact it does:

[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]# 

seems it's indeed quote issue:

<?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]# 

fixed now by using the following converter:

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

to make it work in bash!

Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
omg
  • 136,412
  • 142
  • 288
  • 348
  • possible duplicate of [PHP's file_exists() will not work for me?](http://stackoverflow.com/questions/1287837/phps-file-exists-will-not-work-for-me) – razlebe Oct 28 '11 at 07:51

2 Answers2

3

Try removing the double-quotes, since it's already quoted with single-quotes.

James Skidmore
  • 49,340
  • 32
  • 108
  • 136
  • I need to run exec(),which runs a bash command,either side will fail to work this way. – omg Jun 04 '09 at 01:06
  • Try file_exists() on a different file in a different location to see if it works. If it does work, then your issue is with inaccessibility. If it does not work, then the issue is with the command, and we can work on it from there. Let me know. – James Skidmore Jun 04 '09 at 01:13
  • Good. Is your issue fixed now, or were you having problems with exec()? – James Skidmore Jun 04 '09 at 01:24
  • Great. Post here if you have any more trouble with it. – James Skidmore Jun 04 '09 at 01:47
0

Check the manual for file_exists.

Note this section:

"This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir."

My guess is that you're using <PHP 6.0.0, and you have safe_mode on (it is by default, and is on most hosts). If this is the case, you won't find the file unless it's included in safe_mode_include_dir.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373