PDA

View Full Version : file_exists NEVER works for me


deafboyzaudio
10-21-2010, 04:41 PM
ok i have this code: (test.php)
<?php
$vehicle_thumb = 'http://www.deafboyzaudio.com/videos/uploads/thumbs/subwoofercat.jpg';

if(file_exists($vehicle_thumb)){
echo 'it exists';
}else{
echo 'it dont exist';
}

?>
well if you go to this url:

http://www.deafboyzaudio.com/videos/uploads/thumbs/subwoofercat.jpg
you can see that the file does exist!!!!


Now, if you go to

http://www.deafboyzaudio.com/test.php
that is where the code at the top is held.... and it says that that file DOESNT exist, but i know it does..:mad:

Did some research and found out on php.net that This function returns FALSE for files inaccessible due to safe mode (http://us2.php.net/manual/en/features.safe-mode.php) restrictions. However these files still can be included (http://us2.php.net/manual/en/function.include.php) if they are located in safe_mode_include_dir (http://us2.php.net/manual/en/ini.sect.safe-mode.php#ini.safe-mode-include-dir).of course i do not want to turn safe mode off cuz it can creat tons of other security problems but even so, this file im trying to check if it exist isnt even included.... so does that even matter????

basically i just want to check if a file exists and display a default thumb if not....

how can i do this???? what server settings should i change or maybe i can use a different function???? anyone have any cool custom made ones???

thanks in advance

deafboyzaudio
10-24-2010, 07:07 PM
Anyone???

Still having issues with this and its holdin a main part of my site back...

I've always had a issue with this even with other proven scripts that use if(file_exists(file)){
Do this;
}

Any ideas are appreciated!

davidj
10-25-2010, 06:05 AM
try testing using a relative path

deafboyzaudio
10-25-2010, 05:02 PM
<?php
$path = "http://".$_SERVER['SERVER_NAME']."/videos/uploads/thumbs/";
$vehicle_thumb = $path.'subwoofercat.jpg';

if(file_exists($vehicle_thumb)){
echo 'it exists';
}else{
echo 'it dont exist';
}

?>
this is what i tried and is currently uploaded at the test.php url i gave above....

it return that "it doesnt exist"

i tried all combinations of relative path and they all return "it dont exist"

what possible server settings could it be and how do i get around it??

please shed your knowledge oh great php god...:mrgreen:

davidj
10-25-2010, 05:05 PM
what i mean is try a relative path from the script

$path = "path/path/image.png";

deafboyzaudio
10-26-2010, 05:39 PM
ok i tried that like this:<?php

$vehicle_thumb = "http://".$_SERVER['SERVER_NAME']."/videos/uploads/thumbs/subwoofercat.jpg";

if(file_exists($vehicle_thumb)){

echo 'it exists';

}else{

echo 'it dont exist';

}

?>
still same result... its uploaded on test.php if you want to see....

i even tried it without the $_SERVER['server_name'] and no luck....

On my local machine safe_mode is off and for sh!#s and giggle i turned it on and restarted.... no change

This is an important function and i need it to work, im to the point im prepared to offer a reward for the solution....

davidj
10-28-2010, 06:05 AM
i will write a working solution tonight

davidj
10-28-2010, 06:11 AM
this works for me


//file.php is in the same location as this script
if(file_exists('file.php')){

echo "Yes";

}else{

echo "No";

}

deafboyzaudio
10-31-2010, 06:40 AM
ok your script gave me an idea as it woked.....

i cahnged your "file.php" to a file in a different directory and it did NOT work with an absolute filename like "$path2/videos/etc/file.jpg"

when i searched for the same file as a relative pathname like

"../videos/etc/file.jpg" then it WOULD work as a file_exists function


I have come to the conclusion that absolute filenames dont work for use in the file_exists function on my server....

i think it has something to do with the fact that i am 'including' a variable into a path... which safe_mode prevents... sound right???

Thanks for the help in the right direction david j.... at least now i know a work around:D

davidj
10-31-2010, 03:49 PM
I guess its a security thing. With an absolute path you are going out of the box and then coming back in to the box to check the file.

I think it would work if you chmod the file / dir to 777