[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
On Sun, 5 Jul 2009 14:33:07 -0600, govinda.webdnat...@gmail.com (Govinda) wrote: >I am confusing myself reading the docs just now. > >i.e.: >include_path >basename() >and dirname() > > I had thought from many months ago that > >would include >somefile.php >living in >somedir >regardless from where in the site structure I am calling it. > >Now it does not seem to be doing that. > >What is the safest (portable) way to properly build an include path >*regardless* from where in my site I am calling the include? >If I understand right I can put includes in a dir/ specified by the >include_path setting, but I also want to know how to do this from just >within the root of my virtual server. I have developed a quite sophisticated development system, which enables me to have several different websites using the same software, and allows them all to share the same utilities. I know some of you don't like some of the methods I use, but I think the general idea is relevant to this discussion. Each website has a local directory: D:Websites/Website_1 D:Websites/Website_2 etc. I also have an independent directory containing the common utilities for all the websites: D:Utilities Each website has one or more divisions, corresponding very roughly to photo albums. It also has one directory containing the developmental version of the program, and a second containing the working version of the program e.g. Dev Wkg Album_1 etc. The remote version of each website only has the directories: Wkg Utilities Album_1 etc. a new web page is invoked with the command: http://localhost/Website_1/index.php or http://www.corybas.com/index.php If I want to ensure that a fresh version is loaded I add the parameter: ?new=1, and if I want to invoke the developmental version, I followed this with the parameter: &local_dir=Dev. In either case the program index.php is loaded. This has the following code: The main program begins by checking whether or not it is running on my home PC (using a procedure which caused someone here to say 'Yukk'), but which seems to be both logically sound and reliable. * --- 1.00 Check if running on home PC & set up defaults ---*/ $home = strtr(getcwd(),"\\","/"); // Ensure Home contains forward slashes if (substr($home,0,2) == 'D:') { $is_local = true; if ($local_dir == 'Dev') { $util_dir = $local_dir; } else { $util_dir = 'D:/Websites/Utilities'; } } else { $is_local = false; $util_dir = 'Utilities'; } include ($util_dir.'/Std_utils.php'); // Load standard utilities // Start real work: If the parameter $is_local is set, I have access to a suite of editing facilities, and other private areas. These are not present on the public copy, and there is nothing on any of the menus to suggest that anything is missing. The parameters $is_local and $local_dir are cached, so they only need to be specified when the page is first loaded. I never change the working directory (and it has never yet changed by itself), so I can load anything in any subdirectory simply by specifying the local path. I also realised while I was writing this that there is no real reason to have separate Wkg and Utilities directories (other than that if I only had one version of the program for all local sites, it would make the result of any bug that made it to the working version potentially that much more serious). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
Govinda wrote: On Jul 5, 2009, at 2:33 PM, Govinda wrote: I am confusing myself reading the docs just now. i.e.: include_path basename() and dirname() I had thought from many months ago that would include somefile.php living in somedir regardless from where in the site structure I am calling it. Now it does not seem to be doing that. What is the safest (portable) way to properly build an include path *regardless* from where in my site I am calling the include? If I understand right I can put includes in a dir/ specified by the include_path setting, but I also want to know how to do this from just within the root of my virtual server. -Govinda in my include statement, I am now successfully using: /home/metheuser/public_html/ and am not anticipating moving this site.. but still I am thinking there must be a way to make the code bullet proof to dir/ name changes *after* the virtual server root. Or do people just stop here? Define a constant like APPLICATION_PATH in the bootstrap file of your application. Once it is defined use the paths relative to this constant. This way you can easily move your application around. http://techchorus.net/constants and http://techchorus.net/include-path might be useful to you. -- With warm regards, Sudheer. S Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
Govinda wrote: > > On Jul 5, 2009, at 6:15 PM, Shawn McKenzie wrote: >> >> AFAIK, include '/somedir/somefile.php'; looks for that specific file in >> that specific path because you gave an absolute path. > > Well, that is what I wanted. > So I tried this: > include '/MY_inc_php/GovBC_php_functions.inc'; > but that fails. > So I try this: > include '/home/metheuser/public_html/MY_inc_php/GovBC_php_functions.inc'; > and it works. So, depending upon you include path, yes. The preceding slash states that its an absolute path. Starts at the root / nad the a path after that. > > But if I ever have to move to a server where the "home" part of that > path is not "home", or the "public_html" part of that path is not > "public_html" (I dunno.. I do not run servers), then my includes break. > >> >> If you do include 'somedir/somefile.php'; then it looks in all paths in >> the include path > > Here ^^^ when you say "it looks in all paths in the include path", what > are you talking about? > It seem like you do not mean the path in my include statement itself, > but in some string (path) that is built and stored somewhere else. (?) > Where do I build/store that? > >> and appends somedir/somefile.php. So if your include >> path contained /usr/share/php/PEAR for example and somefile.php was at >> /usr/share/php/PEAR/somedir/ then it would find it. > > > In include_path in php.ini or you can set it in your script. It's the path that PHP looks in when you include a file. Sorry, I thought you knew this and were wanting to know whey one thing worked and one didn't. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
On Jul 5, 2009, at 6:15 PM, Shawn McKenzie wrote: AFAIK, include '/somedir/somefile.php'; looks for that specific file in that specific path because you gave an absolute path. Well, that is what I wanted. So I tried this: include '/MY_inc_php/GovBC_php_functions.inc'; but that fails. So I try this: include '/home/metheuser/public_html/MY_inc_php/ GovBC_php_functions.inc'; and it works. But if I ever have to move to a server where the "home" part of that path is not "home", or the "public_html" part of that path is not "public_html" (I dunno.. I do not run servers), then my includes break. If you do include 'somedir/somefile.php'; then it looks in all paths in the include path Here ^^^ when you say "it looks in all paths in the include path", what are you talking about? It seem like you do not mean the path in my include statement itself, but in some string (path) that is built and stored somewhere else. (?) Where do I build/store that? and appends somedir/somefile.php. So if your include path contained /usr/share/php/PEAR for example and somefile.php was at /usr/share/php/PEAR/somedir/ then it would find it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
On Jul 5, 2009, at 4:17 PM, Michael A. Peters wrote: I use $includeArray[]="/usr/share/pear"; $includeArray[]="/some/other/path"; $includeArray[]="/yet/another/path"; $incPath = impode(':',$includeArray); ini_set("include_path",$incPath); is that ^ something one can generally set on a shared hosting environment? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
Govinda wrote: > I am confusing myself reading the docs just now. > > i.e.: > include_path > basename() > and dirname() > > I had thought from many months ago that > > would include > somefile.php > living in > somedir > regardless from where in the site structure I am calling it. > > Now it does not seem to be doing that. > > What is the safest (portable) way to properly build an include path > *regardless* from where in my site I am calling the include? > If I understand right I can put includes in a dir/ specified by the > include_path setting, but I also want to know how to do this from just > within the root of my virtual server. > > -Govinda AFAIK, include '/somedir/somefile.php'; looks for that specific file in that specific path because you gave an absolute path. If you do include 'somedir/somefile.php'; then it looks in all paths in the include path and appends somedir/somefile.php. So if your include path contained /usr/share/php/PEAR for example and somefile.php was at /usr/share/php/PEAR/somedir/ then it would find it. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
Govinda wrote: in my include statement, I am now successfully using: /home/metheuser/public_html/ and am not anticipating moving this site.. but still I am thinking there must be a way to make the code bullet proof to dir/ name changes *after* the virtual server root. Or do people just stop here? I always define the include path explicitly, and it never includes anything inside the web root, but that's just me. I use $includeArray[]="/usr/share/pear"; $includeArray[]="/some/other/path"; $includeArray[]="/yet/another/path"; $incPath = impode(':',$includeArray); ini_set("include_path",$incPath); Since all my includes are external to the website where they don't ever need to moved no matter how I decide to change things, their paths never move. Served files inside the web root however can move around freely and always find their includes. I admit, keeping all excludes outside the web root can be a bit tedious, but it helps keeps things well organized. There's more than one way to do it though. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
On Jul 5, 2009, at 2:33 PM, Govinda wrote: I am confusing myself reading the docs just now. i.e.: include_path basename() and dirname() I had thought from many months ago that would include somefile.php living in somedir regardless from where in the site structure I am calling it. Now it does not seem to be doing that. What is the safest (portable) way to properly build an include path *regardless* from where in my site I am calling the include? If I understand right I can put includes in a dir/ specified by the include_path setting, but I also want to know how to do this from just within the root of my virtual server. -Govinda in my include statement, I am now successfully using: /home/metheuser/public_html/ and am not anticipating moving this site.. but still I am thinking there must be a way to make the code bullet proof to dir/ name changes *after* the virtual server root. Or do people just stop here? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: best way to properly build an include path *regardless* from where I am calling the include?
On Jul 5, 2009, at 2:33 PM, Govinda wrote: I am confusing myself reading the docs just now. i.e.: include_path basename() and dirname() I had thought from many months ago that would include somefile.php living in somedir regardless from where in the site structure I am calling it. Now it does not seem to be doing that. What is the safest (portable) way to properly build an include path *regardless* from where in my site I am calling the include? If I understand right I can put includes in a dir/ specified by the include_path setting, but I also want to know how to do this from just within the root of my virtual server. -Govinda in my include statement, I am now successfully using: /home/metheuser/public_html/ and am not anticipating moving this site.. but still I am thinking there must be a way to make the code bullet proof to dir/ name changes *after* the virtual server root. Or do people just stop here? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php