Page 1 of 1

using PHP to create text files, some characters are wrong

Posted: Thu Feb 23, 2006 3:06 pm
by eastman
I'm making a php uploader page for my editing dept that will allow them to post articles and make changes directly to the site. They'll need to upload photos in the articles and they won't let me do a slideshow they want the pictures embedded in the articles. I set up Javascript buttons to place image code within the text for them. These articles along with the image code are written to a text file to be included into the article pages. The problem is that when the text file is created the single quotes ( ' ) are replaced by forward slashes folloed by single quotes ( /' ).

Does anyone have any experience with this problem or know of a tutorial that deals with a similar issue?

Javascript:

Code: Select all

function writeImgTag1L(code)
{
var cache = document.thisform.textbox.value;
this.code = code;
document.thisform.textbox.value = cache + ("<div style='float:left; width: px; margin:0px; padding:0px 0px 0px 0px; color:gray; text-size:9px;'><div style='border-style:solid; width:  px; border-color:rgb(129,86,24); border-width:1px;'><img src='<?php echo '<?php echo $rs_img1; ?>'; ?>'></div>  <!--Caption-->  </div>");
document.thisform.textbox.focus();
}
Enter Image Code Button:

Code: Select all

<img onClick="writeImgTag1L('smile1L')" src="float_left.gif" border=0>
The Form:

Code: Select all

<form name= "thisform" action="http://site/upload.php" method="POST" enctype="multipart/form-data">
<p>Upload <br><br>
<input type="hidden" name="MAX_FILE_SIZE" value="2097152" />

<b>Image1</b> &nbsp;&nbsp;<input name="imgfile1" type="file"/> &nbsp;&nbsp;<img onClick="writeImgTag1L('smile1L')" src="float_left.gif" border=0>&nbsp;&nbsp; <br><br>

<b>Text</b><br> &nbsp;&nbsp;<textarea cols="50" rows="15" name="textbox"></textarea><br><br>

<input type="submit" value="Upload" /><br>
The text writing functions (on a separate page):

Code: Select all

$text = $_POST['textbox'];

$textfile = "./dir/dir/text" . $date . ".txt";

$open = fopen("$textfile", "a");

fwrite($open, "\n$text");

fclose($open);
Any help is greatly appreciated. I haven't been able to find anything about this type of problem in my searches. Thank You

Posted: Thu Feb 23, 2006 3:10 pm
by josh
stripslashes()

or turn off magic_quotes

Posted: Wed Mar 15, 2006 2:47 pm
by eastman
It worked great thanks for your help.