Reputation: 119
I have debian machine and my site is in /var/www/laravel-site/ folder. In laravel-site folder i have FILES and PUBLIC folders. How can i output file to FILES folder to protect the file from web reading?
Upvotes: 0
Views: 1465
Reputation: 101
I guess base_path()
will help
Simple usage example:
<?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 = '')
is a Laravel helper function. It gets the path to the base of the install:
function base_path($path = '')
{
return app()->basePath().($path ? '/'.$path : $path);
}
So, to get your /var/www/laravel-site
folder just use
echo base_path();
To get FILES
folder (or whatever path you need inside the Laravel's base) use echo base_path('FILES');
it will output /var/www/laravel-site/FILES
Upvotes: 2