Page 1 of 1

file_exists can't find the file on a webserver

Posted: Thu Dec 13, 2018 7:10 pm
by battlethem
Hey!
I'm making a theme and want to insert a simple 'if' statement for the image.
Basically, if there's a file "image.jpg" in "my_theme/img/", it'll echo 'Apples', otherwise - 'Oranges':

Code: Select all

<!--IMAGE EXISTS-->
<?php if (file_exists('bl-themes/my_theme/img/image.jpg')): ?> 
<?php echo "Apples" ?>
<?php endif ?>

<!--IMAGE DOESN'T EXIST-->
<?php if (!file_exists('bl-themes/my_theme/img/image.jpg')): ?>
<?php echo "Oranges" ?>
<?php endif ?>
The php file is here:
folder/bl-themes/my_theme/php/home.php
The image is here:
folder/bl-themes/my_theme/img/image.jpg

Works well on localhost (with that filepath), although when I upload it to a web server, it doesn't seem to find the image no matter how hard I try to describe the path (the image is there, obviously, but I must be missing something very simple). Tried using THEME_DIR_IMG, HTML_PATH_THEME_IMG, HTML_PATH_ROOT, nothing works on a web server. I'm getting confused, though it must be something silly that I've missed.

Thanks in advance!

Re: file_exists can't find the file on a webserver

Posted: Fri Dec 14, 2018 10:03 am
by Edi
Works on my side.

Is Bludit installed in the root directory or in a subdirectory? Which permissions are set for the image?

Re: file_exists can't find the file on a webserver

Posted: Fri Dec 14, 2018 7:40 pm
by diego
I recommend using the following variables

Code: Select all

<!--IMAGE EXISTS-->
<?php if (file_exists(THEME_DIR.'img/image.jpg')): ?> 
<?php echo "Apples" ?>
<?php endif ?>

<!--IMAGE DOESN'T EXIST-->
<?php if (!file_exists(THEME_DIR.'img/image.jpg')): ?>
<?php echo "Oranges" ?>
<?php endif ?>

Re: file_exists can't find the file on a webserver

Posted: Sun Dec 23, 2018 1:05 pm
by battlethem
Alright this was clearly a mistake I made, it does actually work the way I described it in the first post, have no idea why it didn't work at that moment.
But I agree, using THEME_DIR. is much safer for that reason.
Thanks for the help anyway!