我有debian机器,我的站点在/ var / www / laravel-site /文件夹中。在laravel-site文件夹中,我有FILES和PUBLIC文件夹。如何将文件输出到FILES文件夹以保护文件免受网络阅读?
我想base_path()
会有所帮助
简单用法示例:
<?php
$file = base_path('FILES').'/people.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file, $current);
?>
function base_path($path = '')
是Laravel的辅助函数。它获取安装基础的路径:
function base_path($path = '')
{
return app()->basePath().($path ? '/'.$path : $path);
}
因此,要/var/www/laravel-site
使用您的文件夹echo base_path();
要获取FILES
文件夹(或Laravel基座内所需的任何路径),请使用echo base_path('FILES');
它来输出/var/www/laravel-site/FILES
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句