Hi guys I have a small problem that im hoping someone here can help me with. I am developing a photo website. I have configured the directory structure as such so that each photoset lives at /public_html/photosets/setname/ I have various scripts that I call from the index.php page, each of these scripts lives at public_html/inc/ My problem is that when I try to include the file, like so: include('\inc\script.php'); Code (markup): It will not work, saying it cannot find the file in question. I have tried various other combinations, including referring to the entire URL, but I cannot seem to get it to work. I even considered moving the scripts to the same folder as the calling page, but as there are many photosets, all currently living within their own directory it would be practical and difficult to maintain. I get the feeling im missing something painfully obvious... Can anybody help me work this out? Theres a beer in it if anyone can (but you'll have to come here as I can't drive ) Many thanks Richard
I have. In fact, ive tried both of these: include('inc/script.php'); include('inc\script.php'); Code (markup): Neither of which seem to work.
as far as i know include only works when the file being included is in the same directory as the file that is calling the function.
To get you right, your structure of your webpage is /public_html/index.php /public_html/inc/script.php /public_html/photoset/ /public_html/photoset/set01/ And you are trying to include script.php from index.php? X.Homer.X - you are being completely wrong
It would certainly seem that way. Surely there must be some way to include a script that is elsewhere on the server? I don't want to have to include the script in each individual folder, as this would be a nightmare to maintain, nor do I really want to have all the photosets in the same folder.
yeah this is something that i have come across also, i asked around and noone has an answer to how to incloude a script from a parent or sibling folder. well thats what i was told, im sorry if i dont know every fucking thing about php, i said AS FAR AS I KNOW
I do PHP programmering everyday - and you are able to include files from a different directory - even another server.
@ Denn: The page the include is executed from is: /public_html/photosets/setname/index.php The location of the script is: /public_html/inc/script.php And yes, I am trying to include the script from index.php Thanks
hawkoftheeye: Then I got your problem try include("../../inc/script.php"); X.Homer.X - English is my second language
lol oh sorry, im just so used to everyone knowing english as their first language and speaking it stupidly. also, i never thought that ../../ will would work
Works like a charm Many thanks for all your help guys And the beers yours Denn - you'll have to come and get it though
this does not work with me. this is my folder layout. /public_html/index.php /public_html/includes/script1.php /public_html/includes/script2.php /public_html/admin/index.php im trying to include script2.php from script1.php and including script2.php from admin/index.php do you understand? here script1.php <?php include('script2.php'); ?> Code (markup): admin/index.php <?php include('../includes/script1.php'); ?> Code (markup): thanks.
The error should tell you exactly where it didn't find the specified file. BTW, there's some weird stuff with cases like yours when C.php is included in B.php which is included by A.php. More about that on http://www.php.net/manual/en/function.include.php :
im including my top.php file, and thats working, but in top.php im including config.php, and my css is declared in top.php config and my css are not working, its looking for config in includes/config.php (where it is) but is that looking in the directory of the file being showed? or the directory of the page being included. do you get what im saying, on my admin/ directory my index is calling home/admin/index.php <?php require("../includes/top.php"); require("includes/content.php"); require("../includes/bottom.php"); ?> PHP: home/includes/top.php <?php ob_start(); include('config.php'); ... check if admin redirect to main page ... ?> <head> <link rel=/css.css></link> <!--whatever this code is. css is in home/ directory--> </head> <body> <header> <nav> </body> PHP: How do i make it so the css is included and the config is included?
The CSS path is interpreted by the browser. So the path in the href is relative to the path showing in the address bar. Try to make it relative to the path of the original .php file (not some included file).
what are you talking about. my css file is a .css file not a .php file. it is included using the link rel=stylesheet thing config is being included with .php include
Make it relative to the root of the web server for the CSS file. In english, make it work from /. So if you have your CSS file in /css , the path would be /css/style.css. If its at the top just put /style.css But: <link rel=/css.css></link> That is problematic, should be link rel="stylesheet" href="/css.css" type="text/css" . Far as config.php not being included, I would have to recommend putting it as include ("./config.php"); if that doesn't work, *shrug*