Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Include path with ./ in PHP

Posted on 2009-04-06
6
Medium Priority
?
273 Views
Last Modified: 2012-05-06
If I have an index.php in say:
   c:\wamp\www\myfolder\index.php

that is calling an include() in a sub directory say:
   include_once('subfolder\file.php')   which translates into c:\wamp\www\myfolder\subfolder\file.php

and inside file.php it is calling an include like:
include_once('./different_file.php');

then it goes back to c:\wamp\www\myfolder\ to try and find it . How can I force it so that include('./anything.php') stays inside the most recent folder it was called from, and not the first?

NOTE: It's important to know that I can't edit file.php, It has to maintain it's include with the ./
0
Comment
Question by:level9wizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 24078369
Maybe you can use chdir(), like this:

chdir('subfolder') ;
include_once('file.php');

Then the call to include_once('./different_file.php') will happen within subfolder. In case you use file functions later in the script, you should call chdir() again to set it back to the folder with the script after the include (in index.php):

chdir('..') ;  # one step up

0
 
LVL 11

Author Comment

by:level9wizard
ID: 24078431
>>Maybe you can use chdir()

Problem is, as you saw above, I can't edit file.php - I will consider how I might be able to access this from outside though.
0
 
LVL 20

Expert Comment

by:Gawai
ID: 24078814
>> and inside file.php it is calling an include like:
include_once('./different_file.php');

if u cant edit file.php, how did u know whats inside  that file ?
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 20

Expert Comment

by:Gawai
ID: 24078835
the option is place different_file.php in c:\wamp\www\myfolder
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24079280
>> I can't edit file.php

My suggestion involved editing index.php only...
0
 
LVL 11

Author Comment

by:level9wizard
ID: 24079363
>> My suggestion involved editing index.php only...

Yea sorry I didn't reply to your first remarks properly - In fact you've solved it really. I'll likely have to ask another question based on this one however.
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question