stack01
stack01

Reputation: 101

how to include the file with relative path?

there is a file directory as this:magento\app\design\frontend\default\template\catalog\product\view.phtml

the another file directory as this:magento\blog\wp-blog-header.php

now,if i want to in view.phtml include the wp-blog-header.php.how do i do?thank you.

include('../../../../../../../wordpress/wp-blog-header.php'); 

Upvotes: 3

Views: 564

Answers (3)

iWantSimpleLife
iWantSimpleLife

Reputation: 1954

You could use document root ("$_SERVER["DOCUMENT_ROOT"]"). But that only applies if your app is installed as the only app in the base directory on the web server. If you are running the app in a sub directory, that you need to adjust for that. However, this will make the app less portable as you cannot change the directory easily without having to modify codes.

Based on your example, it seems that you are running Magento, with Magento, you can use "Mage::getBaseDir" method to get the base directory of Magento and relative the include file from that.

Upvotes: 2

ajacian81
ajacian81

Reputation: 7569

That would work, you just have to count the slashes to make sure it's the same as before. However, you can also create a symbolic link in your magento\app\design\frontend\default\template\catalog\product\ directory that points to magento\blog\wp-blog-header.php.

ln -s magento\blog\wp-blog-header.php wp-blog-header.php would do the trick then you can just: include ("wp-blog-header.php");

You can also reference $_SERVER["DOCUMENT_ROOT"] in your include.

Upvotes: 1

Kai Qing
Kai Qing

Reputation: 18833

Personally I would go from root up, not all of this ../../ jazz:

include($_SERVER['DOCUMENT_ROOT'] . "/path-to-include-file");

You sure the wordpress header is compatable with magento? Could face some horrible anomalies there.

Upvotes: 1

Related Questions