473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem: file_exists absolute path

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($f ilename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>

.... and it does not work.
Here it is ...
http://216.12.100.243/test.php

You can see phpinfo() on that server here ...
http://216.12.100.243/phpinfo.php

If I change the first line to ...
$filename = 'path/to/foo.txt';
....it works fine, but I really would like to use an absolute path.

Any help would be greatly appreciated.

Thanks

Jul 17 '05 #1
4 7010
dchaffin <dc******@dream cc.com> wrote:
If I change the first line to ...
$filename = 'path/to/foo.txt';
...it works fine, but I really would like to use an absolute path.


I'm under the impression that you want the path to be an absolute path
in the URL! That is not the same as an absolute path in the filesystem,
unless the document_root is the root of the filesystem. Try prepending
$_SERVER['DOCUMENT_ROOT'] to convert the absolute url path to an
absolute filesystem path.

Jul 17 '05 #2
Thanks for your response.

Hmm ... ok. So that fixed the test file (test.php) ... however, the
actual location I'm trying to use this is in a virtual directory in IIS
and $_SERVER['DOCUMENT_ROOT'] always goes to c:\\inetpub\\ww wroot. I'm
still looking through the server vars to try and find one that
references the virtual dir ... any suggestions?

Jul 17 '05 #3
....or is there somthing other than file_exists (or other filesystem
functions like fopen or is_readable) that maybe uses the url based
paths instead of filesystem based ones?

Jul 17 '05 #4
"dchaffin" <dc******@dream cc.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Thanks for your response.

Hmm ... ok. So that fixed the test file (test.php) ... however, the
actual location I'm trying to use this is in a virtual directory in IIS
and $_SERVER['DOCUMENT_ROOT'] always goes to c:\\inetpub\\ww wroot. I'm
still looking through the server vars to try and find one that
references the virtual dir ... any suggestions?


dirname(__FILE_ _) should do the trick.
Jul 17 '05 #5

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

Similar topics

2
1870
by: Ian Hardcastle | last post by:
I am creating a php script that I can call from a delphi program, this itself is easy as I have already done this. The problem lies within the php script, here is the code that DOESN'T work: <? $temp = $_POST; $uppath = "users/$temp"; clearstatcache(); if(file_exists($uppath)){ unlink($uppath);
1
2277
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))
10
838
by: Hywel | last post by:
this script don't work Script A: set session variable <?php class Page0A { function Page0A(){ $this->init(); $this->save();
8
1715
by: supasnail | last post by:
I have a happily working set of asp pages which read from the database via include file "./_private/include/database.mdb". However, when I try to gain access to this database on pages one folder removed using "../_private/include/database.mdb", the pages won't display. This whole system works fine on my home test server (iis.5.0), but...
6
2780
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 ?
6
3150
by: Jon Slaughter | last post by:
do I have to prefix every absolute path with document root to get it to work? For some reason I thought that prefixing a path with '/' or './' with make it absolute w.r.t to document root but I guess not? e.g., when I do include './Scripts/AddNav.php';
2
1666
by: ELINTPimp | last post by:
Hello all, Have a really interesting problem (at least to me) with my upload_file() function. I have it working now, with a bit of a work around, but would like to know what everyone thinks in regards to this being a bug or perhaps my ignorance. Basically the function takes two arguments, one is the desired file path I want the upload...
20
3649
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:
14
1624
by: shror | last post by:
Hi every body, am trying to create a php script that get a daily picture but am having a problem with that, here is the code am using: <?php $date = date("Y-m-d"); echo "";
0
8328
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...
1
7936
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...
0
8195
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...
0
6581
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...
1
5701
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...
0
5375
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3820
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3845
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.