FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Editing files online





guitarcrazy087
I'm trying to make a script that will allow me to open files, put the contents in a textarea, edit the textarea, and then save the files. What I have so far works fine, except it's messing up the code a little.

I'm using three files to do the whole thing, which probably isn't necessary, but I'm new to PHP so I didn't know of any way better.

Here's the first file:

Code:
<form method="post" action="editpage.php">

<small class="white">Page:</small><br /><input type="text" name="page" /><br /><br />

<input type="submit" value="Select" name="submit" /><br /><br />

</form>


And here's editpage.php:

Code:
<?php

echo '<form method="post" action="pageedited.php">
<textarea rows="60" cols="60" name="content">';

$string = file_get_contents($_POST['page']);
echo $string;

$Pagename = $_POST['page'];

echo '</textarea><br /><br />
<input type="text" value="' . $Pagename . '" name="name" />
<input type="submit" value="Done" />
</form>';

?>


And here's pageedited.php:

Code:
<?php

$File = $_POST['name'];
$Handle = fopen($File, 'w+');
$Content = $_POST['content'];
fwrite($Handle, $Content);
fclose($Handle);

?>


Up till here it works great. However, when I go to the page that I just edited it says this:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/guitarcr/public_html/index.php on line 2

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/guitarcr/public_html/index.php on line 4

So then, if I look at the file contents then, it looks like this:

Code:
<?php
$title=\"Joe Henry-home\";
$Page =\"About\";
include ($_SERVER[\'DOCUMENT_ROOT\'].\'/header.php\'); ?>

<div class=\"articlestart\">
   <h1 class=\"notblog\">About</h1>
   <small class=\"bottomleft\">April 18, 1:39pm</small>
   <small class=\"bottomright\"><a href=\"#comments\"><?php echo $CommentsNum . $Lable; ?></a></small>
</div><div class=\"article\">


</div><div class=\"articleend\"></div>

<?php
include ($_SERVER[\'DOCUMENT_ROOT\'].\'/comments.php\');
include ($_SERVER[\'DOCUMENT_ROOT\'].\'/footer.php\');
?>


So my question is why is it inserting all those "/"? Or is there anything else I'm doing wrong, or is there an easier way to do the whole thing?

Thanks in advance for your help,

Joe
AftershockVibe
Before saving use PHP's stripslashes() function. Basically, PHP is trying to be helpful and escape your quote marks and failing miserably.

Change:
Code:
$Content = $_POST['content'];

to
Code:
$Content = stripslashes($_POST['content']);

and see if that gives you what you want.
guitarcrazy087
Awesome! It works! Thanks so much! PHP coders are deff the coolest!

Haha, thanks! Very Happy
Related topics
FTP and public html problem
question!!!!!!
Free Upload Space for your personal files list!!!
I got a question about the webspace!!
Which Statistics Software should I use?
extern harddsik
phpBB 2.0.18 is RELEASED!
Unzipping zips using Direct Admin...
What are your reasons you are on here
Unzipping files with DirectAdmin
NEW! - Incredibly Low Priced phpBB2 and 3 Services!
Oops i cant edit the HTML files
Editing Scripts Online
online storage to sync files between computers
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.