Help - Search - Members - Calendar
Full Version: Problem With Fle_exists()
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Norm
Hi,
I'm trying to get a hitcounter to work and am having trouble with the file_exists() method failing.
Looking at the folders and files, I think everything is in place. Are there other reasons for file_exists()
to return FALSE? How do I find them and fix them.

Thanks,
Norm


URL: http://****.zxq.net/counters/counter.php?page=test
Returned to browser:
ERROR: Invalid log file!logs/test.txt


PHP code:
...
$logfile = 'logs/' . $page . '.txt';
...
if (file_exists($logfile))
{
...
}
else
{
die('ERROR: Invalid log file!' . $logfile);
}

When I look in the counters folder I see a logs folder. In the logs folder is a file: test.txt
Lua Editor
use a full path.
Norm
QUOTE(Lua Editor @ Jun 24 2010, 02:37 AM) *
use a full path.


How do I find and display the current directory that a .php file sees in PHP? Shouldn't my code be able to refer to a file relative to the current directory vs having to give a full path to the file?


Norm
swordz
The problem is defining the 'current' directory - It can change massively depending on implementation.

Full paths completely remove any ambiguity.

BTW, this is what you were looking for, as a quick Google search would have given you.

swordz
Norm
QUOTE(swordz @ Jun 27 2010, 02:49 PM) *
The problem is defining the 'current' directory - It can change massively depending on implementation.

Full paths completely remove any ambiguity.

BTW, this is what you were looking for, as a quick Google search would have given you.

swordz


Thanks for the response. If I'd known it was called a "Working" directory vs the current directory, I could have looked it up. Correct terminology is very important. I need to learn a new vocabulary for the PHP and linux world.

The problem I've found with full paths is that it ties the application to a specific computer. If the application is to go on different computers, then it has to be tailored for each computer. Maintenance problem. The relative path can be the same on all computers the app is on.
swordz
Have a config/install file to set the path. Or, use __FILENAME__ or a similar constant to get the current directory.

swordz
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.