By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,652 Members | 1,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,652 IT Pros & Developers. It's quick & easy.

load file name from URL cannot select folder

P: 133
Hi everyone,
This is my first PHP project and i am going a little nuts over this. lol.

I am trying to set the php file to load txt files from "files" DIR instead of the current DIR (where php is located) , if you know what i mean.

this loads from current DIR (where php is located)
Expand|Select|Wrap|Line Numbers
  1. //Load filename from URL
  2. if (isset($_GET['page']) && (file_exists($_GET['page'].'.txt'))) //If the url contains an existing filename
  3. {
  4.     $filename = $_GET['page'].'.txt';  //Load it
  5. }
  6. else
  7. {
  8.     $filename = 'files/'.'index.txt';  //Otherwise, default to index.txt
  9.     $htmltitle= 'Home';
  10. }
this script will load $filename = 'files/'.'index.txt'; but it will not get other txt files unless they are in current DIR
i have tried many different ways but without success..
Apr 16 '10 #1
Share this Question
Share on Google+
4 Replies

P: 227
$filename = 'files/'.'index.txt';

is a relative path from the current php file you are executing so

you can use a absolute path to the file or make the relative path
with respect to the current php file

Apr 16 '10 #2

P: 133
Thanks but i am still confused, care to elaborate please?
Apr 16 '10 #3

P: 227
can you show me your folder structure

Apr 16 '10 #4

P: 133

files/ is where i would like to keep the text files.
Apr 16 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.