Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,672 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,166 people online right now. Registration is fast and FREE... Join Now!




Online Text Editor

 
Reply to this topicStart new topic

Online Text Editor, Online Text Editor won't save updates

spykat
post 4 Jul, 2007 - 01:42 PM
Post #1


New D.I.C Head

*
Joined: 4 Jul, 2007
Posts: 2


My Contributions


Hello, and happy 4th of July smile.gif

I got this script from here:
Online File Editing Script

It looks to be JUST what I need, but while it will load the specified text file, it will not save the edits.
It just reloads the page with the prior text still intact.

While I am using the same code as the author, I believe, I will post it below in the event I missed something.

CODE

<?php
$loadcontent = "testit.txt";
    if($save_file) {
        $savecontent = stripslashes($savecontent);
        $fp = @fopen($loadcontent, "w");
        if ($fp) {
        fwrite($fp, $savecontent);
        fclose($fp);
        } else
        echo "Error opening file";
                }
    $fp = @fopen($loadcontent, "r");
        $loadcontent = fread($fp, filesize($loadcontent));
        $loadcontent = htmlspecialchars($loadcontent);
        fclose($fp);

?>
<form method=post action="<?=$_SERVER['PHP_SELF']?>">
<textarea name="savecontent" cols="70" rows="25"><?php echo $loadcontent; ?> </textarea>
<br>
<input type="submit" name="save_file" value="Save">  
</form>


I am on a Linux server, and I tried setting the permissions to both the PHP file AND the text file (testit.txt) to 755, 666, and finally, to 777 just to rule out a permissions thing.

I would have posted this question on the board where the program was initially posted, except that another user was having the same problem as me, and no answer was ever given after several months.

Any clues people?

Thx,
Rick
User is offlineProfile CardPM

Go to the top of the page

fyrestorm
post 4 Jul, 2007 - 03:28 PM
Post #2


D.I.C Lover

Group Icon
Joined: 4 Apr, 2002
Posts: 3,103



Thanked 2 times

Dream Kudos: 228
My Contributions


for beginners, the proper permissions need to be set on any text file you'll be editing and those permissions are 777. In the meantime, I'll upload to my server and see what I can discover.
User is offlineProfile CardPM

Go to the top of the page

spykat
post 4 Jul, 2007 - 05:05 PM
Post #3


New D.I.C Head

*
Joined: 4 Jul, 2007
Posts: 2


My Contributions


Hi Fyrestorm,

Thanks for the fast reply.
I think it would still be cool to get that program to working, but in the meantime, I got this little ol' program that does the same thing:

CODE

<?
if($_POST['Submit']){
$open = fopen("testit.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "<div style='font-family:tahoma,sans-serif;background-color:#7fa3df;border:1px solid #000000;padding:10px;color:#f0f0f0;line-height:175%;font-size:12pt;'>";
echo "File has been Updated.<br />";
echo "File Now Reads:<br />";
$file = file("testit.txt");
foreach($file as $text) {
echo $text."<br />";
}
echo "<p style='color:#f0f0f0;'><a href=\"./\">click here to view the live updated webpage</a></p>";
echo "<p style='color:#f0f0f0;'><a href=\"./edit.php\">click here to edit again</a></p>";
echo "</div>";
}else{
$file = file("testit.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


Pretty sweet huh?
User is offlineProfile CardPM

Go to the top of the page

Styx
post 4 Jul, 2007 - 06:31 PM
Post #4


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


If you look at the if condition in the original, it seems to be using register_globals. You could try changing it to account for being off.
User is offlineProfile CardPM

Go to the top of the page

ap0c0lyps3
post 7 Jul, 2007 - 01:02 PM
Post #5


D.I.C Head

Group Icon
Joined: 19 Jun, 2007
Posts: 79



Dream Kudos: 25
My Contributions


Why don't you try FCKeditor, I used it on a CMS for the Kenwyn Martial Arts Centre.

Heres an example
CODE
if(!isset($_POST['FCKeditor1'])) {
@$value = file_get_contents("Source/".$edit);

include("Source/fckeditor/fckeditor.php");

$quer = $db->query("SELECT * FROM links WHERE url = '".$edit."'");
$rowa = mysql_fetch_array($quer);

echo '<form action="?action=admin&edit='.$edit.'" method="post">'.
     '<p><input type="textbox" name="filen" size="20" value="'.$rowa[name].'"/></p>';
$editor = new FCKeditor('FCKeditor1');
$editor->BasePath = "/fckeditor/";
$editor->Height = 500;
$editor->Width = 500;
$editor->Value = $value;
$editor->Create();
?>
<input type="submit" value="Save">
</form>
<?php
}
else {
    $db->query("UPDATE `links` SET `name` = '".$_POST['filen']."' WHERE `url` = `".$_GET['edit']."`");
    $file = fopen("Source/".$edit, 'w');
    fwrite($file, $_POST['FCKeditor1']);
    fclose($file);
    echo "<b>File saved</b>";
}
}

You first need to download FCKeditor first though
User is offlineProfile CardPM

Go to the top of the page

Styx
post 7 Jul, 2007 - 02:50 PM
Post #6


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


He could also use the one I submitted, just options
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:08AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month