Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a folder inside my theme where I hold some txt files which I am including in a theme. The problem is that before including txt file I need to check if it does exist. I fail checking it the following way and have no idea why it wont work, always returns false.

$themeLocation = get_bloginfo('template_url');
$fileName1 = $themeLocation.'/txtfolder/file1.txt';

if(is_file($fileName1)){
   echo 'It does exist';
} else {
   echo 'Error';
}
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You are trying to check it by URL, which makes no sense to is_file() which expects local path. By the way I'd use file_exists() instead.

Try:

$fileName1 = TEMPLATEPATH . '/txtfolder/file1.txt';
share|improve this answer
    
Thank you so much! Works now! –  Alex Sep 5 '11 at 20:35
    
@Rarst Is there any particular reason why you'd use file_exists() over is_file() in this case? –  w3d Sep 5 '11 at 22:18
    
@w3d not really, just more used to see file_exists() check used (or at least used first). Hadn't really looked into nuances. –  Rarst Sep 5 '11 at 22:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.