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 :: laravel seconds to hours minutes seconds 
Php :: get month first date and last date in php 
Php :: cake php 2.x joins 
Php :: How do I get the current date and time in PHP? 
Php :: read pdf text in php 
Php :: laravel 8 get app folder 
Php :: php array filter only null 
Php :: Undefined index: id 
Php :: carbon equal dates 
Php :: install php 7.3 ubuntu 
Php :: redirect woocommerce thank you 
Php :: php datetime sub minutes 
Php :: use js in php 
Php :: alerta con php 
Php :: ajax get request in laravel 
Php :: create listener using laravel 
Php :: installing bootstrap on laravel8 
Php :: laravel 5.8 cors 
Php :: php auto redirect 
Php :: php session destroy 
Php :: Server Requirements in laraavel 9 
Php :: php convert string to boolean 
Php :: php get highest key in array 
Php :: paystack gateway integration laravel 
Php :: convert to json php 
Php :: string remove last two characters php 
Php :: php new stdClass object 
Php :: laravel folder permission 
Php :: php check if object is empty 
Php :: array constant in php 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =