473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

file_exists works inconsistently?

I'm using PHP 4.4.4-8 on Debian Linux on a low traffic site, and need
to detect if a file exists, and if so, unlink it.
I am mystified as to why the file_exists() function does not work in
one particular section of code, yet does work in another section. The
unlink() function similarly works in one section, but not the other.

I have read other posts in this group where others have had trouble
with the file_exists() function, but none seemed to help with my
problem; so here goes...

Here is the code snippet that does not work, which includes a test to
verify if 'safe mode' is off:

if ($debug) {
echo "<br>fullname of target file = ".$fullname;
echo "<br>File exists? ";
if (file_exists($fullname)) {
echo "YES!";
} else {
echo "NO!!";
}
echo "<br>Safe mode on? ";
if (ini_get('safe_mode')) {
echo "YES!";
} else {
echo "NO!!";
}
echo "<br>(exiting...)";
exit;

Here is the (partial) output:

fullname of target file = /Net/delta/home/ehringer/MAELab/RickLIMStest/
GABA_JSakai/GABRGI/rs10033451/caller_1_results/
GABRGI_rs10033451_080307_VS_cda01_cda02_cda03_cda0 4.txt
File exists? NO!!
Safe mode on? NO!!
(exiting...)

By cut-&-paste into a console window with ls -la command, I verify the
full pathname is correct.

If anyone has any ideas about this, I would be most grateful...

Thanks,
Rick Casey

Aug 5 '08 #1
3 2032
On Aug 5, 8:31*pm, rickcasey <caseyr...@gmail.comwrote:
I'm using PHP 4.4.4-8 on Debian Linux on a low traffic site, and need
to detect if a file exists, and if so, unlink it.
I am mystified as to why the file_exists() function does not work in
one particular section of code, yet does work in another section. The
unlink() function similarly works in one section, but not the other.

I have read other posts in this group where others have had trouble
with the file_exists() function, but none seemed to help with my
problem; so here goes...

Here is the code snippet that does not work, which includes a test to
verify if 'safe mode' is off:

* * * * if ($debug) {
* * * * * * * * echo "<br>fullname of target file = ".$fullname;
* * * * * * * * echo "<br>File exists? ";
* * * * * * * * if (file_exists($fullname)) {
* * * * * * * * * * * * echo "YES!";
* * * * * * * * } else {
* * * * * * * * * * * * echo "NO!!";
* * * * * * * * }
* * * * * * * * echo "<br>Safe mode on? ";
* * * * * * * * if (ini_get('safe_mode')) {
* * * * * * * * * * * * echo "YES!";
* * * * * * * * } else {
* * * * * * * * * * * * echo "NO!!";
* * * * * * * * }
* * * * * * * * echo "<br>(exiting...)";
* * * * * * * * exit;

Here is the (partial) output:

fullname of target file = /Net/delta/home/ehringer/MAELab/RickLIMStest/
GABA_JSakai/GABRGI/rs10033451/caller_1_results/
GABRGI_rs10033451_080307_VS_cda01_cda02_cda03_cda0 4.txt
File exists? NO!!
Safe mode on? NO!!
(exiting...)

By cut-&-paste into a console window with ls -la command, I verify the
full pathname is correct.

If anyone has any ideas about this, I would be most grateful...

Thanks,
Rick Casey
Try the new PHP4 version there are many bugfixes in file_exists.
Do the same test but with is_file(). Did you find the file with the
glob?

Alexander
Aug 6 '08 #2
rickcasey wrote:
I'm using PHP 4.4.4-8 on Debian Linux on a low traffic site, and need
to detect if a file exists, and if so, unlink it.
I am mystified as to why the file_exists() function does not work in
one particular section of code, yet does work in another section. The
unlink() function similarly works in one section, but not the other.

I have read other posts in this group where others have had trouble
with the file_exists() function, but none seemed to help with my
problem; so here goes...

Here is the code snippet that does not work, which includes a test to
verify if 'safe mode' is off:

if ($debug) {
echo "<br>fullname of target file = ".$fullname;
echo "<br>File exists? ";
if (file_exists($fullname)) {
echo "YES!";
} else {
echo "NO!!";
}
echo "<br>Safe mode on? ";
if (ini_get('safe_mode')) {
echo "YES!";
} else {
echo "NO!!";
}
echo "<br>(exiting...)";
exit;

Here is the (partial) output:

fullname of target file = /Net/delta/home/ehringer/MAELab/RickLIMStest/
GABA_JSakai/GABRGI/rs10033451/caller_1_results/
GABRGI_rs10033451_080307_VS_cda01_cda02_cda03_cda0 4.txt
File exists? NO!!
Safe mode on? NO!!
(exiting...)

By cut-&-paste into a console window with ls -la command, I verify the
full pathname is correct.

If anyone has any ideas about this, I would be most grateful...
1.) add a trim:
if (file_exists($fullname)) {
< if (file_exists(trim($fullname))) {
to make sure there are no whitespaces in $fullname, so that you actually
test for two different paths.
2.) any fancy encodings around ? Probably not, but if so that might affect
interpretation of paths
3.) what about the permissions of containing folders ? everything readable
and the web server is allowed to change into _all_ containing folders ?
(guessing that you run the script under a web servers process...)

arkascha

Aug 6 '08 #3
On Aug 5, 7:31 pm, rickcasey <caseyr...@gmail.comwrote:
I'm using PHP 4.4.4-8 on Debian Linux on a low traffic site, and need
to detect if a file exists, and if so, unlink it.
I am mystified as to why the file_exists() function does not work in
one particular section of code, yet does work in another section. The
unlink() function similarly works in one section, but not the other.

I have read other posts in this group where others have had trouble
with the file_exists() function, but none seemed to help with my
problem; so here goes...
<snip>

So you run file_exists on the same file twice in your code without
calling clearstatcache() - I suspect you should RTFM for both
functions.

C.
Aug 6 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chann Becker | last post by:
My current setup: WWW Server: Windows 2000 Server, SP4 IIS5 PHP 4.3.4 File Server Windows 2000 Server, SP4
2
by: Andrew Crowe | last post by:
Hi guys, I've created this little function to check whether a user has uploaded a file with the same name as an existing file, and if so rename it to file-1.jpg, file-2.jpg etc. ...
10
by: Google Mike | last post by:
{NOTE: I have PHP 4.2.2 for RH9 Linux.} Anyone have a better file_exists() out there? Even if you use shell out tricks with Linux using the `command` trick, I'd be interested to see what you...
1
by: Hinrich Specht | last post by:
Hello, I have a problem using file_exists. I want to use file_exists to dertermine if a product-image is available or not to show either the product-image or a standard-image. This is the code:...
3
by: annie | last post by:
Hi I've got two linux boxes running redhat9 and either PHP Version 4.2.2 or PHP Version 4.3.7. The file structure is set up the same on both machines and both files exist. The problem is not...
5
by: lkrubner | last post by:
I've written some template code and one thing I'm trying to protect against is references to images that don't exist. Because users have the ability to muck around with the templates after...
4
by: dchaffin | last post by:
I'm having a problem using file_exists with an absolute path and I can not figure out why. I tried the exact example that is on www.php.net ... <?php $filename = '/path/to/foo.txt'; if...
6
by: +86 | last post by:
i encountered this problem: "include('inc.php')" will work problely but "include('./inc.php') doesn't work .. both file_exists('inc.php') or file_exists('./inc.php') didn't return the right...
20
by: Bob Sanderson | last post by:
This is my code: if (file_exists($Fname)) { echo "<td>$Fname exists</td>"; } else { echo "<td>$Fname does not exist</td>"; } $Fname is the full path to the file I'm trying to verify. When I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.