Jump to content

Relative Path


ainoy31

Recommended Posts

Directory structure:

 

/home/~test/public_html/soap/

    .../xml/

    .../bin/

    .../products/browser/

 

In file /home/~test/public_html/soap/bin/products/browser/test.php, I include another file and call it's function:

require("../../xml/processXML.php");

$xmlData = generateXML(....);

 

In the /home/~test/public_html/soap/xml/processXML.php, I have the following code:

function generateXML()
{
     exec("../bin/code.cur");
}

 

The problem is the exec("../bin/code.cur") fails of the relative path issue.  I did a getcwd() before the exec() and it returned /home/~test/public_html/soap/bin/products/browser.  I have tried using dirname() and no help.  I hope this is clear enought to understand where I am coming from.

 

Thank you.

AM

 

 

 

Link to comment
Share on other sites

You could change the CWD to the directory of the current file using __FILE__ like this:

 

<?php
$old_dir = getcwd();
chdir(dirname(__FILE__));

echo getcwd(); // do your stuff
exec("../bin/code.cur");

chdir($old_dir);
echo getcwd(); // all back to what it was again
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.