Jump to content

File Structure Navigation


DarkElf

Recommended Posts

This is going to take a while to explain, but here goes;I'm building a basic content management system which works something like this; There is a single file called page.php which contains a template for the users website. When someone browsing the site opens a page it calls page.php and supplies it some variables which it uses to add the content of that particular page to the template, the content is stored in files in a folder called 'content'.Here's an example, the user calls index.php which looks something like this:

<?php//set variables$page = index;//call page.phpinclude ('page.php');?>

page.php looks a little like this:

Some irrelevant html<?php//add content of page$content = file_get_contents('content/'.$page);echo $content;?>Some more irrelevant html

content/index is just a file of no defined type that contains nothing more than text.So far this all works wonderfully, now onto the content management bit. There is another folder called 'cms', in which the content management system lives. The structure of the pages works almost identically to the users site, except the content is added to each page by an include statement instead of file_get_contents, this is so I can include some php in the page content.There is a page called update.php which contains a text area, based upon variables passed to it a php script should open and print one of the content files such as the example above, the user can the modify the content of this text area and submit it to another page for processing. The variable which calls the content of the text area is passed in a different way here because obviously i don't want a php file in my cms for every page in the user site, instead it is passed using a query string (e.g. ?index is added to the end of the url), i've checked and this is being passed correctly. Here's what should happen, bear in mind that update.php is located in the directory root/cms/ where root is the location of the users website.1. user goes to www.mywebsite.com/cms/update.php?index2. update.php calls page.php and passes it the $page=update variable (note that this is page.php for the cms and is in the cms directory not the page.php file for the users website).3. page.php calls content/update4. content/update contains a text area which contains the following code to load the index content file:

<?php//get $file variable$file = $_SERVER['QUERY_STRING'];//get contents of file$filecontent = file_get_contents('../../content/'.$file);echo $filecontent;?>

It should work, I can't find any holes, but there is an error on the file_get_contents line:Warning: file_get_contents(../../content/index): failed to open stream: No such file or directory in /root/cms/content/updateWhy? What is wrong? I'm stuck.What is really annoying is that if I create a php file which should emulate update.php after all the includes have been performed it works like a charm. I know I've gone on a bit but if anyone manages to read through all of this then please let me know if you spot anything.

Link to comment
Share on other sites

Doh!Spent days struggling with the problem.... finally resort to spending about 30 mins writing it out in detail here for some help.... and guess what?No more than a few minutes after I've finished typing do I spot my error!The file get contents line of that last code block should have read as follows:$filecontent = file_get_contents('../content/'.$file)Just goes to show how the tiniest mistakes can cause the biggest problems!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...