473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PHP 5 relative paths don't work??

Max
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

Jul 28 '06 #1
6 2723
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
Jul 28 '06 #2

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

Jul 28 '06 #3
On 27 Jul 2006 21:26:36 -0700, "Max" <ma*@kipness.comwrote:
>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>
Jul 28 '06 #4
"Max" <ma*@kipness.comwrote:
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
Jul 28 '06 #5
Max

Miguel Cruz wrote:
"Max" <ma*@kipness.comwrote:
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

Jul 28 '06 #6
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" <ma*@kipness.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>
Miguel Cruz wrote:
>"Max" <ma*@kipness.comwrote:
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

Jul 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Doug | last post by:
If I were to write an include with a relative path like include("../conf/config.php"); What is the use? As far as I understand it, the path is relative to the first script that is called by...
7
by: jason | last post by:
I am getting twisted by the possibility that my virtual includes which currently work great on non-domain remote IP will crash if I purchase a domain and point it to one of my designated...
3
by: epigram | last post by:
I've got a javascript menu that uses an external .js file. In the .js file, there is a function that gets called by each of my .html pages to build up the menu for the page. The way I want to...
1
by: olorin_press | last post by:
I have an Access 2000 database in which I display various graphics for each record. I store all the images in a folder ("Images") which is a subdirectory to the directory in which the .mdb is...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
11
by: MBS | last post by:
I am playing around with some PHP code. I want to put in an include() function so I can include existing HTML code and output it to the browser. Lo and behold PHP does not support relative paths...
8
by: JJ | last post by:
I'm confused about paths. I have a functionn that uses the mappath method, which I think requires a virtual path (is that the same as a relative path?). But this doesn't always work as the...
15
by: Lars Eighner | last post by:
Aside from the deaths of a few extra electrons to spell out the whole root relative path, is there any down side? It seems to me that theoretically it shouldn't make any difference, and it would...
2
by: BD | last post by:
Hi there. Using 8.2 on Windows. I have a situation where I have a db backup, which I want to deploy to a group of developer workstations. The target directory for the database files will be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.