473,401 Members | 2,146 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,401 software developers and data experts.

require_once problem

I hava several php files in different folders.

I tried to use relative paths. But when I call a script from another
folder that has another depth, it cannot find the files that are
embedded via require once within the included file.

sample:

fileA.php (in the root dir!)
-----
require_once 'common_inc.php';
....
-----

classes/fileB.php (in /classes)
-----
require_once '../fileA.php';
....
-----
No it trys to find the 'common_lib in the /classes folder insted of the
root dir.
Well, I tried now to specify absolute paths like
"http://127.0.0.1:8080/projectname/common_inc.php"
But it cannot be included then. Thats the browser string of the file.
Why doesn't it work?
How can I solve this problem?
It doesn't matter for me if relative or absolute paths specifications
are used. It should only work :)
thanks in advance,
Lars
Jul 17 '05 #1
7 3306
Lars Plessmann wrote:
Well, I tried now to specify absolute paths like
"http://127.0.0.1:8080/projectname/common_inc.php"
But it cannot be included then. Thats the browser string of the file.
Why doesn't it work?


Use filesystem paths:

require_once 'C:/htdocs/common_inc.php';
require_once 'C:/htdocs/classes/fileB.php';
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
Pedro Graca wrote:
Lars Plessmann wrote:
Well, I tried now to specify absolute paths like
"http://127.0.0.1:8080/projectname/common_inc.php"
But it cannot be included then. Thats the browser string of the file.
Why doesn't it work?

Use filesystem paths:

require_once 'C:/htdocs/common_inc.php';
require_once 'C:/htdocs/classes/fileB.php';


problem: I develop on windows and my host is unix.
how to handle this?
Jul 17 '05 #3
Lars Plessmann wrote:
Pedro Graca wrote:
Lars Plessmann wrote:
Well, I tried now to specify absolute paths like
"http://127.0.0.1:8080/projectname/common_inc.php"
But it cannot be included then. Thats the browser string of the file.
Why doesn't it work?

Use filesystem paths:

require_once 'C:/htdocs/common_inc.php';
require_once 'C:/htdocs/classes/fileB.php';


problem: I develop on windows and my host is unix.
how to handle this?


Maybe like this (PHP 5)?
<?php
if (stripos(PHP_OS, "win") === false) {
require_once '/htdocs/common_inc.php';
} else {
require_once 'C:/htdocs/common_inc.php';
}
?>
stripos() is available from PHP 5

PHP_OS is a core predefined constant
http://www.php.net/manual/en/reserve...tants.core.php

if you don't have PHP 5 try:

<?php
function my_stripos($haystack, $needle, $offset=0) {
return strpos(strtoupper($haystack), strtoupper($needle), $offset);
}
?>

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #4

"Lars Plessmann" <La************@gmx.de> wrote in message
news:40***********************@newsread4.arcor-online.net...
I hava several php files in different folders.

I tried to use relative paths. But when I call a script from another
folder that has another depth, it cannot find the files that are
embedded via require once within the included file.

sample:

fileA.php (in the root dir!)
-----
require_once 'common_inc.php';
...
-----

classes/fileB.php (in /classes)
-----
require_once '../fileA.php';
...
-----
No it trys to find the 'common_lib in the /classes folder insted of the
root dir.
Well, I tried now to specify absolute paths like
"http://127.0.0.1:8080/projectname/common_inc.php"
But it cannot be included then. Thats the browser string of the file.
Why doesn't it work?
How can I solve this problem?
It doesn't matter for me if relative or absolute paths specifications
are used. It should only work :)
thanks in advance,
Lars


$_SERVER["DOCUMENT_ROOT"] should give you the top-level document root
("/var/www/html" or "c:\inetpub\wwwroot", say) - if your include storage is
consistent, you could trust that.

Garp
Jul 17 '05 #5
> I hava several php files in different folders.

I tried to use relative paths. But when I call a script from another
folder that has another depth, it cannot find the files that are
embedded via require once within the included file.

sample:

fileA.php (in the root dir!)
-----
require_once 'common_inc.php';
...
-----

classes/fileB.php (in /classes)
-----
require_once '../fileA.php';
...
-----


my idea:
-----
require_once dirname(__FILE__).'../fileA.php';
-----

dirname(__FILE__)." relative paths ". " file ";

--
CHARA=>TOMeK
Jul 17 '05 #6
> my idea:
-----
require_once dirname(__FILE__).'../fileA.php';
-----

dirname(__FILE__)." relative paths ". " file ";


This is good:
-----
require_once dirname(__FILE__).'/'.'../fileA.php';
-----

dirname(__FILE__).'/'." relative paths ". " file ";

Pozdrawiam,
CHARA=>TOMeK
Jul 17 '05 #7
"Lars Plessmann" <La************@gmx.de> wrote in message
news:40***********************@newsread4.arcor-online.net...
I hava several php files in different folders.

I tried to use relative paths. But when I call a script from another
folder that has another depth, it cannot find the files that are
embedded via require once within the included file.

sample:

fileA.php (in the root dir!)
-----
require_once 'common_inc.php';
...
-----

classes/fileB.php (in /classes)
-----
require_once '../fileA.php';
...
-----
No it trys to find the 'common_lib in the /classes folder insted of the
root dir.
What was the current directory when you tried this? What was the
include_path setting when you tried this?
Well, I tried now to specify absolute paths like
"http://127.0.0.1:8080/projectname/common_inc.php"
But it cannot be included then. Thats the browser string of the file.
Why doesn't it work?
You use file system paths, not URLS
How can I solve this problem?
It doesn't matter for me if relative or absolute paths specifications
are used. It should only work :)


We can't really say until you tell us about your include path and identify
the directory in which the script initially started.

- Virgil
Jul 17 '05 #8

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

Similar topics

6
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the...
0
by: NotGiven | last post by:
Below is a code snippet I am having a hard time with. I rerquire code1.php and code 2.php. code1.php contains some variables the code needs. code2.php contains some functions I call from the...
3
by: Justin L. Kennedy | last post by:
I am having a problem with multiple includes. A.php require_once on two files: B.php then C.php C.php require_once on B.php again Then I get a message: Warning: main(../../B.php): failed...
5
by: mostof | last post by:
I'm facing a problem with require_once... Instead of actually including the file i'm requiring, it just dumps it out as text... other functions are working quite well... the code look like...
11
by: Kimmo Laine | last post by:
I'm flipping my wig here, people. I'm using classes and making each class a file. when I'm including dependet classess, I use require_once to avoid multiple declarations - yet they happen. I put...
3
by: Tyno Gendo | last post by:
Has anyone come across this problem with require_once? I was working on my local machine with apache and have included a file like this: require_once "welcome_patient.php"; Works fine, the...
6
by: Shelly | last post by:
Here is a crazy question that has happend to me once before. I have an include file for the connection information to the server. It is like this: $hostname= "the_server_location"; $database...
3
by: Peter Wang | last post by:
Hi, all. I recently encountered a very annoying problem while using Zend Framework(ZF). We use ZF in our web application, and it works fine at the beginning, but later when concurrent...
6
by: Royan | last post by:
Ok the problem is quite hard to explain, but i'll try to keep it as simple as i can. Imagine I have the following structure of my files and folders: /root/global.inc |__/files/foo.php...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.