For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > July 2006 > PHP 5 relative paths don't work??









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PHP 5 relative paths don't work??
Max

2006-07-28, 3:57 am

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

lorento

2006-07-28, 3:57 am

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


Noodle

2006-07-28, 3:57 am


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

David Quinton

2006-07-28, 3:57 am

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>
Miguel Cruz

2006-07-28, 7:58 am

"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
Max

2006-07-28, 6:57 pm


Miguel Cruz wrote:
> "Max" <max@kipness.com> wrote:
>
> 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

Christina

2006-07-28, 6:57 pm

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.googlegroups.com...
>
> Miguel Cruz wrote:
>
>
> __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
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com