Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to chdir() more than once

Posted on 2009-04-06
2
Medium Priority
?
958 Views
Last Modified: 2012-05-06
I have a file.php that before I include it, use chdir() to resource from a subfolder. However file.php calls chdir() as well, for its includes and it throws:

Warning: chdir() [function.chdir]: No error (errno 0) in C:\wamp\www\a\test.php on line 4
Warning: include(test2.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\a\test.php on line 5
Warning: include() [function.include]: Failed opening 'test2.php' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\rob\a\test.php on line 5

Below is the three files i'm using to test this:
------------------ C:\wamp\www\index.php -------------------------
<?php
 
echo 'Changing dir to a...<br />';
chdir('a/');
include('test.php');
 
?>
 
------------------ C:\wamp\www\a\test.php -------------------------
I'm in folder 'a'<br />
<?php 
echo 'changing folder to b...';
chdir('b/');
include ('test2.php');
 ?>
 
 
------------------ C:\wamp\www\b\test2.php -------------------------
i'm in folder b

Open in new window

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 Comments
 
LVL 17

Accepted Solution

by:
nplib earned 2000 total points
ID: 24081014
it's because you have to orient our self to the new directory

so the first chdir()

puts you from

EXAMPLE:
/public_html/www

to
/public_html/www/a

which is now your working directory

so chir('b/'); being called after words is trying to change to

/public_html/www/a/b
which probably doesn't exist.

you need to  change it to

chdir('../b/');

which will then change it to
/public_html/www/b



0
 
LVL 10

Expert Comment

by:Phatzer
ID: 24081034
I'm not sure include will take in to account the chdir before it because I've never needed to do it that way. Also, what is the reason you are doing it that way instead of:

include('a/test.php');

or

include ('b/test2.php');

?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 dynamically set the form action using jQuery.
Suggested Courses

609 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