Search
 
SCRIPT & CODE EXAMPLE
 

PHP

create a text file in laravel

namespace AppHttpControllers;
use File;
class FileController extends Controller
{
    public function downloadJSONFile(){
      $data = json_encode(['Element 1','Element 2','Element 3','Element 4','Element 5']);
      $file = time() .rand(). '_file.json';
      $destinationPath=public_path()."/upload/";
      if (!is_dir($destinationPath)) {  mkdir($destinationPath,0777,true);  }
      File::put($destinationPath.$file,$data);
      return response()->download($destinationPath.$file);
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: php move file to another directory 
Php :: php days in month 
Php :: php fix array index 
Php :: php get value from url 
Php :: regex php password 
Php :: laravel fire event 
Php :: json to array php 
Php :: wordpress add_submenu_page 
Php :: take file data in variable php 
Php :: ubuntu laravel storage permission 
Php :: php remove leading zeros 
Php :: how to go to another folder in php 
Php :: PHP mysqli_close function 
Php :: laravel collection prepend 
Php :: PHP File Read Modes 
Php :: set unique value validation for laravel form request 
Php :: laravel 8: bootstrap 
Php :: php oop 
Php :: create new laravel 9 project 
Php :: woocommerce show data to cart page 
Php :: comparing floats php 
Php :: token delete laravel 
Php :: php check for null 
Php :: php var in string 
Php :: json_encode() in php 
Php :: steps to create laravel project 
Php :: call model function in controller laravel 
Php :: array associativo php 
Php :: how to save the variable from query in mysql with php 
Php :: laravel assets path 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =