Page 1 of 1

Quick file read question

Posted: Wed Apr 30, 2008 9:27 pm
by UnGround
This seems very simple to me, but i can't figure out what is wrong. I had some (working) code that looked like so:

Code: Select all

$filen="./../file.txt";
$fh=fopen($filen,"r");
...
Where the text file was outside of the web directory (security). I am changing my site structure so this PHP file is now one level lower in the web directory. I changed the code accordingly:

Code: Select all

$filen="./../../file.txt";
$fh=fopen($filen,"r");
...
But now I receive the following error:

fopen(./../../file.txt) [function.fopen]: failed to open stream: No such file or directory

Does anyone know the reason for this?

Thanks!

Re: Quick file read question

Posted: Wed Apr 30, 2008 9:36 pm
by ggggqqqqihc
Your code seems no problem. Maybe it happened in another place. What's the warning or error info? You'd better provide some more code.

Re: Quick file read question

Posted: Wed Apr 30, 2008 10:00 pm
by UnGround
Thats honestly all the relevant information.

My dir structure looks something like this:
/var/html
/var/html/inc
/var/html/js
/var/html/css
etc

originally, I had file.txt in /var/file.txt, and my config.php in /var/html/config.php

Now, I have file.txt in /var/file.txt and config.php in /var/html/inc/config.php

Changing the dir link to ./../../file.txt does not seem to work. If I copy file.txt to /var/html/file.txt and change the code back to $filen="./../file.txt"; it works. With filt.txt in both directories and $filen="./../../file.txt" it does not work, and I get "no such file or directory" error.

It is a very odd bug...