PHP 5 relative paths don't work??

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-28-2006
Max
 
Posts: n/a
Default PHP 5 relative paths don't work??

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

Reply With Quote
  #2 (permalink)  
Old 07-28-2006
lorento
 
Posts: n/a
Default Re: PHP 5 relative paths don't work??

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


Reply With Quote
  #3 (permalink)  
Old 07-28-2006
Noodle
 
Posts: n/a
Default Re: PHP 5 relative paths don't work??


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';

Reply With Quote
  #4 (permalink)  
Old 07-28-2006
David Quinton
 
Posts: n/a
Default Re: PHP 5 relative paths don't work??

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>
Reply With Quote
  #5 (permalink)  
Old 07-28-2006
Miguel Cruz
 
Posts: n/a
Default Re: PHP 5 relative paths don't work??

"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
Reply With Quote
  #6 (permalink)  
Old 07-28-2006
Max
 
Posts: n/a
Default Re: PHP 5 relative paths don't work??


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

Reply With Quote
  #7 (permalink)  
Old 07-28-2006
Christina
 
Posts: n/a
Default Re: PHP 5 relative paths don't work??

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
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:57 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0