Jump to content


Photo

PHP Includes Through Directories


  • Please log in to reply
4 replies to this topic

#1 bachya

bachya
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 June 2006 - 04:24 PM

Hi all,

I have this bit of code:

<?php
    if (isset($_GET[article]))
    {
        if (file_exists($_GET[issue].'/'.$_GET[article].'.html'))
            include($_GET[issue].'/'.$_GET[article].'.html');
        else
            include($_GET[issue].'/default.html');
    } 
    else 
    {
        include($_GET[issue].'/default.html');
    }
?>

What I need is this: if I have a URL that's something like - www.mydomain.com/articles.php?issue=sp06&article=1 - I want to use both the "issue" and "article" variables to descend into my directory structure and include the necessary article. The directory is something like this:

articles.php
sp06 ->
1.html
2.html
...
fl06 ->
1.html
2.html
...

...and so on.

The above implementation is incorrect - perhaps my knowledge of concatenation in PHP is flawed...

Can anyone point me in the right direction? Let me know if the above info is not adequate.

Thanks.

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 21 June 2006 - 04:36 PM

What exactly is the error you are getting? It looks like the file that will be included will be something like this:
public_html/issue_dir/article_html.html
I am assuming the public_html. At any rate, the problem I see is that you're GET[ ] needs to have 's around the strings, so $_GET['article'] instead of $_GET[article]. Otherwise I'm not sure what else is wrong.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 21 June 2006 - 04:40 PM

Maybe try echo'ing your path to see how it looks? eg;
echo $_GET['issue'].'/'.$_GET['article'].'.html');
Your code looks fine so....what exactly do you meen by?
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] The above implementation is incorrect[/quote]

#4 bachya

bachya
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 June 2006 - 04:44 PM

[!--quoteo(post=386475:date=Jun 21 2006, 12:36 PM:name=Buyocat)--][div class=\'quotetop\']QUOTE(Buyocat @ Jun 21 2006, 12:36 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What exactly is the error you are getting? It looks like the file that will be included will be something like this:
public_html/issue_dir/article_html.html
I am assuming the public_html. At any rate, the problem I see is that you're GET[ ] needs to have 's around the strings, so $_GET['article'] instead of $_GET[article]. Otherwise I'm not sure what else is wrong.
[/quote]

The scary thing is that there is no error - it's just a blank page (with my main CSS layout). I tried adding 's around the variable names in $_GET[], but that didn't seem to help.

[!--quoteo(post=386476:date=Jun 21 2006, 12:40 PM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 21 2006, 12:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Maybe try echo'ing your path to see how it looks? eg;
echo $_GET['issue'].'/'.$_GET['article'].'.html');
Your code looks fine so....what exactly do you meen by?
[/quote]

Unfortuantely, that ALSO gives a blank page...it's baffling, because that should be right. I'm assuming it's incorrect because the desired results aren't appearing. :( I noticed that it echoes output in the ELSE part of the branch to check if the file exists or not...if that helps at all.

#5 bachya

bachya
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 June 2006 - 05:05 PM

Okay, so I finally was able to echo my path, piece by piece, and this code:

echo $_GET['issue'].'/'.$_GET['article'].'.html'

...gave this result:

sp06/1.html (when my URL was www.mydomain.com/articles.php?issue=sp06&issue=1)

Still no dice - as I said before, the problem is (I believe) coming in the part of the code below that is the ELSE branch to the "file_exists" function:

<?php
    if (isset($_GET['article']))
    {
        if (file_exists($_GET['issue'].'/'.$_GET['article'].'.html'))
            include($_GET['issue'].'/'.$_GET['article'].'.html');
        else
            echo $_GET['issue'].'/'.$_GET['article'].'.html';
    } 
    else 
    {
        include($_GET[issue].'/default.html');
    }
?>

Since it's echoing the path correctly, that must mean that "file_exists" is having a problem with it. Unfortunately, I'm newbie enough to PHP that that doesn't help me.

EDIT: Okay, it definitely is "file_exists", because if I remove that, it includes correctly. However, now I've just left a huge hole in my site...sheesh. Does anyone know why this function is giving me so much trouble?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users