Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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);
    }
}
Source by www.phpzone.in #
 
PREVIOUS NEXT
Tagged: #create #text #file #laravel
ADD COMMENT
Topic
Name
9+7 =