title: Save textarea content in file with JS and PHP
body: <p>I have a problem with textarea content which I want to save it in a file.
  So, an user could write in that textarea some HTML,PHP,JS and/or other tags and it wants to save in a file.
  First, I declared a variable in JS which takes the textarea value and send via ajax to PHP.
  The PHP creates a file and insert textarea content in that file.</p>
  
  <p>If I write a simple PHP/HTML/JS code in textarea, the created and saved file doesn't contain anything. It is empty (if I use PHP code in textarea) or sometimes if I write HTML tags in textarea.
  Look inside my script :</p>
  
  <p><a href="http://pastebin.com/z6CbSNKC" rel="nofollow">http://pastebin.com/z6CbSNKC</a></p>
  
  <p>So, what's the problem ? The JS is a problem or PHP code ?</p>
  
  <p>Code from pastebin:</p>
  
  <pre><code>/* HTML code */
  Filename with extension : 
  &lt;input type="text" placeholder="ex: test.css" id="titlecopypaste" /&gt;&lt;br/&gt;
  &lt;textarea cols="60" rows="10" placeholder="Insert code here" id="content"&gt;&lt;/textarea&gt;&lt;br/&gt;
  &lt;select id="choose"&gt;
  &lt;option value="public" selected="selected"&gt;Public&lt;/option&gt;
  &lt;option value="private"&gt;private&lt;/option&gt;
  &lt;option value="both"&gt;Public si private&lt;/option&gt;
  &lt;/select&gt;
  &lt;center&gt;&lt;button id="submitcopypaste"&gt;Done&lt;/button&gt;&lt;br/&gt;
  &lt;p id="status_create"&gt;&lt;/p&gt;
  &lt;/center&gt;
  
  
  
  
  /* Javascript code */
  $("#submitcopypaste").click(function()
  {
      var fisier=$("#titlecopypaste").val();
      var content=$("#content").text();
      var select=$("#choose").val();
      $.ajax({
          type:"POST",
          url:"include/uploadtxt.php",
          data:"fis="+fisier+"&amp;cont="+content+"&amp;sel="+select,
          success:function(ev)
          {
              $(this).hide();
              $("#status_create").html(ev);
          }
  });
  
  
  
  
  
  /* PHP code */
  session_start();
  include('Files.php'); //the class created by
  include('connect.php');
  $status="";
  if(isset($_POST['fis'],$_POST['cont'],$_POST['sel']))
      {
          $obj=new Files();
          $file=$_POST['fis'];
          $content=$_POST['cont'];
          $selected=$_POST['sel'];
  
          switch($selected)
              {
              case "public":{
                  $status=$obj-&gt;createfile("../diskuser/_public/".$file, $content);break;
              }
              case "private":{
                  if(isset($_SESSION['utilizator'],$_SESSION['parola']))
                      {
                  $cer=mysql_query("select * from user where nickname='".$_SESSION['user']."' and password='".$_SESSION['parola']."'");
                  if($cer)
                      {
                          while($info=mysql_fetch_array($cer))
                              {
                                  $status=$obj-&gt;createfile("../diskuser/".$info['nickname']."/".$file, $content);break;
                              }
                      }
                  else
                      {
                          $status="Connection error!";
                      }
                      }
                  else
                      {
                          $status="The session has been expired !";
                      }
                      break;
              }
              case "both":{
                  $status=$obj-&gt;createfile("../diskuser/_public/".$file, $content);
                  $cer=mysql_query("select * from user where nickname='".$_SESSION['user']."' and password='".$_SESSION['parola']."'");
                  if($cer)
                      {
                          while($info=mysql_fetch_array($cer))
                              {
                                  $status=$obj-&gt;createfile("../diskuser/".$info['nickname']."/".$file, $content);break;
                              }
                      }
                  else
                      {
                          $status="Database connection error !";
                      }
                      break;
              }
              }
      }
  else
      {
          $status="Invalid data !";
      }
      echo $status;
      });
  </code></pre>