This is a discussion on PHP 5 relative paths don't work?? within the PHP Language forums, part of the PHP Programming Forums category; Hello - Just switched to PHP 5 and just realized that all my scripts with relative paths for require statements no ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello -
Just switched to PHP 5 and just realized that all my scripts with relative paths for require statements no longer work unless I put the absolute path. Usually, if the file is in the same directory I would us the following statement: require 'file.php'; Now I'm having to use: require '/var/www/html/file.php'; Do I just need to convert everthing to absolute, or is there something I'm missing somewhere? Thanks, Max |
|
|||
|
Check your php.ini there is include_path configuration. Add your
directory you want as relative part. Other method use dirname() function. E.g for include file in the same directory : include dirname(__FILE__)."/file.php"; --- http://www.cookdojo.com http://www.deshot.com Max wrote: > Hello - > > Just switched to PHP 5 and just realized that all my scripts with > relative paths for require statements no longer work unless I put the > absolute path. Usually, if the file is in the same directory I would us > the following statement: > > require 'file.php'; > > Now I'm having to use: > > require '/var/www/html/file.php'; > > Do I just need to convert everthing to absolute, or is there something > I'm missing somewhere? > > Thanks, > Max |
|
|||
|
Max wrote: > Hello - > > Just switched to PHP 5 and just realized that all my scripts with > relative paths for require statements no longer work unless I put the > absolute path. Usually, if the file is in the same directory I would us > the following statement: > > require 'file.php'; > > Now I'm having to use: > > require '/var/www/html/file.php'; > > Do I just need to convert everthing to absolute, or is there something > I'm missing somewhere? > > Thanks, > Max Have you tried using '.' to represent the current directory? eg. require './file.php'; |
|
|||
|
On 27 Jul 2006 21:26:36 -0700, "Max" <max@kipness.com> wrote:
>Hello - > >Just switched to PHP 5 and just realized that all my scripts with >relative paths for require statements no longer work unless I put the >absolute path. Usually, if the file is in the same directory I would us >the following statement: > >require 'file.php'; > >Now I'm having to use: > >require '/var/www/html/file.php'; > >Do I just need to convert everthing to absolute, or is there something >I'm missing somewhere? If it's like v4, you can also use .htaccess if you can't get at php.ini. php_value include_path .:/usr/lib/php:/home/xxxx/yyyy I think you need to be using mod_apache and not as cgi. <http://www.zend.com/manual/configuration.changes.php>refers. -- Locate your Mobile phone: <http://www.bizorg.co.uk/news.html> Great gifts: <http://www.ThisBritain.com/ASOS_popup.html> |
|
|||
|
"Max" <max@kipness.com> wrote:
> Just switched to PHP 5 and just realized that all my scripts with > relative paths for require statements no longer work unless I put the > absolute path. Usually, if the file is in the same directory I would us > the following statement: > > require 'file.php'; > > Now I'm having to use: > > require '/var/www/html/file.php'; > > Do I just need to convert everthing to absolute, or is there something > I'm missing somewhere? I have observed some flakiness in the way PHP5 is handling the current working directory. With PHP4 it always seems to be the directory that holds the current script, as tested with the simple script: <? system('pwd') ?> With PHP5 I had observed a couple days ago that the value of PWD actually changed during the course of script execution sometimes, despite my not doing anything overt to cause that. This seemed to me like a bug, but I didn't have time then to look into it further. Trying now, with PHP5 on this machine, PWD always seems to be Apache's value of DocumentRoot (no, not $ENV['PWD']). This breaks many scripts that expect to be able to refer to data files relative to themselves. If PWD cannot be trusted, then setting the include_path to include '.' doesn't help (but the __FILE__ tricks will). miguel -- Photos from 40 countries on 5 continents: http://travel.u.nu Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco Airports of the world: http://airport.u.nu |
|
|||
|
Miguel Cruz wrote: > "Max" <max@kipness.com> wrote: > > Just switched to PHP 5 and just realized that all my scripts with > > relative paths for require statements no longer work unless I put the > > absolute path. Usually, if the file is in the same directory I would us > > the following statement: > > > > require 'file.php'; > > > > Now I'm having to use: > > > > require '/var/www/html/file.php'; > > > > Do I just need to convert everthing to absolute, or is there something > > I'm missing somewhere? > > I have observed some flakiness in the way PHP5 is handling the current > working directory. > > With PHP4 it always seems to be the directory that holds the current > script, as tested with the simple script: > > <? system('pwd') ?> > > With PHP5 I had observed a couple days ago that the value of PWD > actually changed during the course of script execution sometimes, > despite my not doing anything overt to cause that. This seemed to me > like a bug, but I didn't have time then to look into it further. > > Trying now, with PHP5 on this machine, PWD always seems to be Apache's > value of DocumentRoot (no, not $ENV['PWD']). This breaks many scripts > that expect to be able to refer to data files relative to themselves. > > If PWD cannot be trusted, then setting the include_path to include '.' > doesn't help (but the __FILE__ tricks will). __FILE__ seems to work ok for require and file, but for fopen it fails no matter how I construct it. Based on the work arounds listed above (which I appreciate), I guess there is no way to get PHP 5 to work like PHP 4 in which it can figure out the location of files relative to itself just by listing the file name. Would this be considered a bug? Thanks, Max |
|
|||
|
I've been spending hours trying to debug a navigational setup for our
intranet site and include file access. I have run into several similar problems. Even though doc_root is set in php.ini, it doesn't work right (or at least the way the php manual says it's supposed to work). I have tried hard-coding, various http globals with no consistent responses. I'm glad to know it's not just me... "Max" <max@kipness.com> wrote in message news:1154098204.137747.193360@i3g2000cwc.googlegro ups.com... > > Miguel Cruz wrote: >> "Max" <max@kipness.com> wrote: >> > Just switched to PHP 5 and just realized that all my scripts with >> > relative paths for require statements no longer work unless I put the >> > absolute path. Usually, if the file is in the same directory I would us >> > the following statement: >> > >> > require 'file.php'; >> > >> > Now I'm having to use: >> > >> > require '/var/www/html/file.php'; >> > >> > Do I just need to convert everthing to absolute, or is there something >> > I'm missing somewhere? >> >> I have observed some flakiness in the way PHP5 is handling the current >> working directory. >> >> With PHP4 it always seems to be the directory that holds the current >> script, as tested with the simple script: >> >> <? system('pwd') ?> >> >> With PHP5 I had observed a couple days ago that the value of PWD >> actually changed during the course of script execution sometimes, >> despite my not doing anything overt to cause that. This seemed to me >> like a bug, but I didn't have time then to look into it further. >> >> Trying now, with PHP5 on this machine, PWD always seems to be Apache's >> value of DocumentRoot (no, not $ENV['PWD']). This breaks many scripts >> that expect to be able to refer to data files relative to themselves. >> >> If PWD cannot be trusted, then setting the include_path to include '.' >> doesn't help (but the __FILE__ tricks will). > > > __FILE__ seems to work ok for require and file, but for fopen it fails > no matter how I construct it. > > Based on the work arounds listed above (which I appreciate), I guess > there is no way to get PHP 5 to work like PHP 4 in which it can figure > out the location of files relative to itself just by listing the file > name. > > Would this be considered a bug? > > Thanks, > Max > |