laravel 獲取默認(rèn)欄目路徑函數(shù)說明
1、app_path()
app_path函數(shù)返回app目錄的絕對(duì)路徑:
$path = app_path();
運(yùn)行結(jié)果:G:\phpstudy\wwwroot\Laravel\app
你還可以使用app_path函數(shù)為相對(duì)于app目錄的給定文件生成絕對(duì)路徑:
$path = app_path('Http/Controllers/Controller.php');
2、base_path()
base_path函數(shù)返回項(xiàng)目根目錄的絕對(duì)路徑:
$path = base_path();
運(yùn)行結(jié)果:G:\phpstudy\wwwroot\Laravel
你還可以使用base_path函數(shù)為相對(duì)于應(yīng)用目錄的給定文件生成絕對(duì)路徑:
$path = base_path('vendor/bin');
3、config_path()
config_path函數(shù)返回應(yīng)用配置目錄的絕對(duì)路徑:
$path = config_path();
運(yùn)行如果:G:\phpstudy\wwwroot\Laravel\config
4、database_path()
database_path函數(shù)返回應(yīng)用數(shù)據(jù)庫目錄的絕對(duì)路徑:
$path = database_path();
運(yùn)行結(jié)果:G:\phpstudy\wwwroot\Laravel\database
5、public_path()
public_path函數(shù)返回public目錄的絕對(duì)路徑:
$path = public_path();
運(yùn)行結(jié)果:G:\phpstudy\wwwroot\Laravel\public
6、storage_path()
storage_path函數(shù)返回storage目錄的絕對(duì)路徑:
$path = storage_path();
運(yùn)行結(jié)果:G:\phpstudy\wwwroot\Laravel\storage
還可以使用storage_path函數(shù)生成相對(duì)于storage目錄的給定文件的絕對(duì)路徑:
$path = storage_path('app/file.txt');