PDA

View Full Version : Include trong thư mục ngang cấp cùng host



vnpress
26-05-2010, 13:18
Mình sử dụng Apache là webserver.

Cấu hình thư mục chứa web là D:\www.

Mình có Main project chứa ở: D:\www\main
Và Sub project chứa ở: D:\www\sub

Trong một file .php của Sub mình muốn include một file trong D:\www\main\libraries thì làm được không và đường dẫn thế nào? (bạn vui lòng viết giúp mình câu lệnh include).

Cảm ơn các bạn nhiều!

ngoc_viet08
26-05-2010, 14:19
dùng __FILE__ bạn sẽ có đường dẫn của D:\www\sub .
lọc bỏ sub và thay bằng main\libraries
include it :D



//config
define( 'DS', DIRECTORY_SEPARATOR );

$sub_url = dirname(__FILE__);
echo $sub_url; // D:\www\sub
$lib_url = str_replace('sub','main'.DS.'libraries',$sub_url);
echo $lib_url ; // D:\www\main\libraries
//include($lib_url.DS.'somefile.php');

chưa test nữa :D

tham khảo
http://php.net/manual/en/language.constants.predefined.php
http://php.net/manual/en/function.dirname.php

kenphan19
27-05-2010, 09:04
Thử xem :D
set_include_path
(PHP 4 >= 4.3.0, PHP 5)
set_include_path — Sets the include_path configuration option


set_include_path('D:\www');
include 'main/x.php';
include 'sub/y.php';