0

I am developing CMS kind of website where I am using rich text editor to edit text of templates and I am try to save edited content on text files. Its working fine but when large amount of data send for save then some paragraph contents are truncated. I am using ajax to send data into back-end.

This is my php code for writing into the file

<?php
$file = fopen("../include/banner.html","w+");

     fwrite($file,$_POST['param']);

fclose($file);
?>

my ajax code

var editor_data = CKEDITOR.instances.banner.getData(); 
   alert(editor_data); 

var param = 'param=' + editor_data; 

  $.ajax( { 
    type: "POST", 
    url:'./php/banner.php', 
    dataType:'html', 
    data: param, });

Can anyone help me to provide solution for writing large amount of data into text files using php. If am enter jast 2-3 lines its working fine but when more than 20 lines its not working properly some contents are truncated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ashish Gupta
  • 372
  • 1
  • 4
  • 11

1 Answers1

0

I would serialize your data when you write it to the file.

file_put_contents( "../include/banner.html", json_encode($_POST) );

So that way your data is still in JSON format when your ajax call parses it.

Justin Workman
  • 380
  • 3
  • 6