views:

365

answers:

2

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!

+3  A: 

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

James Skidmore
I need to run exec(),which runs a bash command,either side will fail to work this way.
Shore
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
no,it's quote issue,see my update.
Shore
Good. Is your issue fixed now, or were you having problems with exec()?
James Skidmore
yes,fixed,updated again:)
Shore
Great. Post here if you have any more trouble with it.
James Skidmore
A: 

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
seems it's not the case.
Shore