3

Has anyone got any idea to why doesn't the following work ?

$file = 'images/thumbs/1%20-%20Copy.jpg';
if(!file_exists($file)){
 die('NOT THERE');  
}

echo 'Yes its there.';

The problem is with the spaces. I have checked the file exists,dbl checked n triple checked im going nuts. :(

Help

2
  • btw I have double checked the case sensitivity aswell Commented Nov 30, 2010 at 15:44
  • This is a relative path, what means, that it is resolved against the current working directory (getcwd()). Did you checked the absolute path also (realpath())? Commented Nov 30, 2010 at 15:46

3 Answers 3

7

file_exists works on the file system and not via HTTP. So %20 will not be recognized as space but literally as %20; use spaces instead:

$file = 'images/thumbs/1 - Copy.jpg';
Sign up to request clarification or add additional context in comments.

2 Comments

... and for the sake of completeness: the URL for a file with actual %20 on its name should be images%2Fthumbs%2F1%2520-%2520Copy.jpg ;-)
@Álvaro G. Vicario: It would rather be images/thumbs/1%2520-%2520Copy.jpg.
1
$file = rawurldecode('images/thumbs/1%20-%20Copy.jpg');

Comments

1

try these two

$file = 'images/thumbs/1\ -\ Copy.jpg';
$file = 'images/thumbs/1 - Copy.jpg';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.