Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 17th, 2005, 06:41 AM
Lars Plessmann
Guest
 
Posts: n/a
Default 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
  #2  
Old July 17th, 2005, 06:41 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: require_once problem

Lars Plessmann wrote:[color=blue]
> 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?[/color]

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 :
  #3  
Old July 17th, 2005, 06:41 AM
Lars Plessmann
Guest
 
Posts: n/a
Default Re: require_once problem

Pedro Graca wrote:
[color=blue]
> Lars Plessmann wrote:
>[color=green]
>>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?[/color]
>
>
> Use filesystem paths:
>
> require_once 'C:/htdocs/common_inc.php';
> require_once 'C:/htdocs/classes/fileB.php';
>
>[/color]

problem: I develop on windows and my host is unix.
how to handle this?
  #4  
Old July 17th, 2005, 06:41 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: require_once problem

Lars Plessmann wrote:[color=blue]
> Pedro Graca wrote:
>[color=green]
>> Lars Plessmann wrote:
>>[color=darkred]
>>>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?[/color]
>>
>>
>> Use filesystem paths:
>>
>> require_once 'C:/htdocs/common_inc.php';
>> require_once 'C:/htdocs/classes/fileB.php';
>>
>>[/color]
>
> problem: I develop on windows and my host is unix.
> how to handle this?[/color]

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 :
  #5  
Old July 17th, 2005, 06:41 AM
Garp
Guest
 
Posts: n/a
Default Re: require_once problem


"Lars Plessmann" <Lars.Plessmann@gmx.de> wrote in message
news:40c4d9ad$0$26367$9b4e6d93@newsread4.arcor-online.net...[color=blue]
> 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[/color]

$_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


  #6  
Old July 17th, 2005, 06:42 AM
CHARA=>TOMeK
Guest
 
Posts: n/a
Default Re: require_once problem

> I hava several php files in different folders.[color=blue]
>
> 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';
> ...
> -----
>[/color]

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

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

--
CHARA=>TOMeK


  #7  
Old July 17th, 2005, 06:42 AM
CHARA=>TOMeK
Guest
 
Posts: n/a
Default Re: require_once problem

> my idea:[color=blue]
> -----
> require_once dirname(__FILE__).'../fileA.php';
> -----
>
> dirname(__FILE__)." relative paths ". " file ";[/color]

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

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

Pozdrawiam,
CHARA=>TOMeK
  #8  
Old July 17th, 2005, 06:42 AM
Virgil Green
Guest
 
Posts: n/a
Default Re: require_once problem

"Lars Plessmann" <Lars.Plessmann@gmx.de> wrote in message
news:40c4d9ad$0$26367$9b4e6d93@newsread4.arcor-online.net...[color=blue]
> 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.[/color]

What was the current directory when you tried this? What was the
include_path setting when you tried this?
[color=blue]
> 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?[/color]

You use file system paths, not URLS
[color=blue]
> How can I solve this problem?
> It doesn't matter for me if relative or absolute paths specifications
> are used. It should only work :)[/color]

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

- Virgil


 

Bookmarks

Thread Tools

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

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles