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.
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 :
http://pastebin.com/z6CbSNKC
So, what's the problem ? The JS is a problem or PHP code ?
Code from pastebin:
/* HTML code */
Filename with extension :
<input type="text" placeholder="ex: test.css" id="titlecopypaste" /><br/>
<textarea cols="60" rows="10" placeholder="Insert code here" id="content"></textarea><br/>
<select id="choose">
<option value="public" selected="selected">Public</option>
<option value="private">private</option>
<option value="both">Public si private</option>
</select>
<center><button id="submitcopypaste">Done</button><br/>
<p id="status_create"></p>
</center>
/* 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+"&cont="+content+"&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->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->createfile("../diskuser/".$info['nickname']."/".$file, $content);break;
}
}
else
{
$status="Connection error!";
}
}
else
{
$status="The session has been expired !";
}
break;
}
case "both":{
$status=$obj->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->createfile("../diskuser/".$info['nickname']."/".$file, $content);break;
}
}
else
{
$status="Database connection error !";
}
break;
}
}
}
else
{
$status="Invalid data !";
}
echo $status;
});
I think you may need encode the textarea content before send it.
精彩评论