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