Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // https://www.geeksforgeeks.org/how-to-append-data-in-json-file-through-html-form-using-php/
- $data = $_POST;
- $log_path = ROOT_DIR.'react_logs';
- $log_file = $log_path.'/logs.json';
- $this->_maybe_create_upload_path($log_path); // Create Folder 'react_log'
- if(!file_exists($log_file)){
- fopen(rtrim($log_path, '/').'/'.'logs.json', 'w') or die("Unable to open file!");
- }
- if(file_exists($log_file))
- {
- // $inp = file_get_contents($log_file);
- // if(!empty($inp)){
- // $tempArray = json_decode($inp, TRUE);
- // array_push($tempArray, json_decode($data['logs'], TRUE));
- // file_put_contents($log_file, json_encode($tempArray));
- // }else{
- // $logs = array();
- // $logs[] = json_decode($data['logs'], TRUE);
- // file_put_contents($log_file, json_encode($logs));
- // }
- $tempArray = array();
- $inp = file_get_contents($log_file);
- if(!empty($inp)){
- $tempArray = json_decode($inp, TRUE);
- }
- $tempArray[] = json_decode($data['logs'], TRUE);
- file_put_contents($log_file, json_encode($tempArray));
- echo 'Log Added.';
- }else{
- echo 'Log File Not Create in Server';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement