473,800 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>fullna me of target file = ".$fullname ;
echo "<br>File exists? ";
if (file_exists($f ullname)) {
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_result s/
GABRGI_rs100334 51_080307_VS_cd a01_cda02_cda03 _cda04.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 2071
On Aug 5, 8:31*pm, rickcasey <caseyr...@gmai l.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>fullna me of target file = ".$fullname ;
* * * * * * * * echo "<br>File exists? ";
* * * * * * * * if (file_exists($f ullname)) {
* * * * * * * * * * * * 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_result s/
GABRGI_rs100334 51_080307_VS_cd a01_cda02_cda03 _cda04.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>fullna me of target file = ".$fullname ;
echo "<br>File exists? ";
if (file_exists($f ullname)) {
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_result s/
GABRGI_rs100334 51_080307_VS_cd a01_cda02_cda03 _cda04.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($f ullname)) {
< if (file_exists(tr im($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...@gmai l.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
4532
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
3761
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. clearstatcache(); if(file_exists("$BasePath/$FileName.jpg")){ $extra=1; while(file_exists("$BasePath/$FileName-$extra.jpg")){
10
3999
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 came up with. I have this remotely mounted SMB shares on Linux, stuck in my /mnt directory, and the docs tell me that file_exists() doesn't work on that. When I tested this, I found this to be true. Therefore, I need an alternative.
1
2285
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: $image = "../../artimages/".$item_code.".jpg"; if (file_exists($image))
3
7972
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 file specific and on both machines seq_tables is a symbolic link to another location. It makes no difference to either version of php whether I use double or single quotes when asigning a value to $filename. Nor does it matter whether I use...
5
8714
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 everything's been set up, there is a chance they'll delete an image or ruin some tag after the web designer has set up everything perfectly. I want the software to catch mistakes like that and, at the very least, not show broken links. On the control...
4
7021
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 (file_exists($filename)) { echo "The file $filename exists";
6
2788
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 value.this always show "file doesn't exists' my environment is win2003+iis+php5 how to fix it ?
20
3670
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 run the script, I get the following output:
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.