Quick file read question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
UnGround
Forum Newbie
Posts: 3
Joined: Wed Apr 30, 2008 9:18 pm

Quick file read question

Post 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!
ggggqqqqihc
Forum Newbie
Posts: 5
Joined: Mon Apr 28, 2008 8:08 pm
Location: China

Re: Quick file read question

Post 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.
UnGround
Forum Newbie
Posts: 3
Joined: Wed Apr 30, 2008 9:18 pm

Re: Quick file read question

Post 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...
Post Reply