Jump to content

html source for editing


ZulfadlyAshBurn

Recommended Posts

"Edit it on the page itself" - what do you mean by this exactly, in-place of each piece of content, or the whole source code is just presented for editing?

 

 

pagelime.com

Generally I think people ask how to do something on a support forum because they want to implement it themselves.

Link to comment
Share on other sites

@Rifts I want to create something like that. I have tried many third party softwares but im still unable to achieve it :(

 

@MrAdam What i meant is that they are able to upload their own files and edit them (the files uploaded) on the website itself as a whole source using third party software like tinymce.

Link to comment
Share on other sites

You need to read the contents of the file in via a function such as file_get_contents, display it within a textarea, and then overwrite it again using a function such as file_put_contents. You'd need to consider how you'd securely implement it, so they're not able to access each others files.

 

You can integrate TinyMCE if you wish, but that's handled/attached client-side (i.e. by JavaScript), the PHP process wouldn't change.

 

Your best bet is to approach it one step a time. First get the source in a textarea. Then write it back to the file. Then implement the security. Then look into TinyMCE.

Link to comment
Share on other sites

You need to read the contents of the file in via a function such as file_get_contents, display it within a textarea, and then overwrite it again using a function such as file_put_contents. You'd need to consider how you'd securely implement it, so they're not able to access each others files.

 

You can integrate TinyMCE if you wish, but that's handled/attached client-side (i.e. by JavaScript), the PHP process wouldn't change.

 

Your best bet is to approach it one step a time. First get the source in a textarea. Then write it back to the file. Then implement the security. Then look into TinyMCE.

 

how to i echo the source in to textarea?

this is what i amble to docan you help me with the teaxtarea?

<?php 
$file = file_get_contents ('index.php'); 
Echo $file; 
?> 

Link to comment
Share on other sites

You just quite literally echo it between the tags. In-case there's a closing </textarea> within the source however, you need to escape the data to entities with htmlentities:

 

<textarea><?php echo htmlentities($str); ?></textarea>

 

The mark-up will still appear the same within the textarea, however if you look at the source you'll notice - for example - a <p> tag looks like <p>. This means when the user saves, you need to decode the data before you write it back to the file with html_entity_decode.

Link to comment
Share on other sites

when the user save, it saves the file but when it is viewed, it looks different o.0

 

edit.php

<?php 
$file = file_get_contents ('index2.php', true);
?>
<html>
<head>
<title>Editor</title>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
</head>
<body>
<form method="post" action="save.php">
	<p>
		My Editor:<br />
<textarea name="editor1"><?php echo htmlentities($file); ?></textarea>
<script type="text/javascript">
window.onload = function()
{
	CKEDITOR.replace( 'editor1' );
};
</script>
	</p>
	<p>
		<input type="submit" />
	</p>
</form>
</body>
</html>

 

save.php

<?php
$editor_data = $_POST[ 'editor1' ];
$a = htmlentities($editor_data);
$b = html_entity_decode($a);
$fileurl = "index2.php";
$fp = fopen($fileurl, 'w');
fwrite($fp, $b);
fclose($fp);

?>

 

Link to comment
Share on other sites

$editor_data = $_POST[ 'editor1' ];
$a = htmlentities($editor_data);
$b = html_entity_decode($a);

 

The problem is that you're encoding the encoded data (so it's encoded twice), then decoding it back to the once encoded data. You have to remember that $_POST['editor1'] has already been encoded, you just need to decode it:

 

<?php

// get the encoded data
$editor_data = $_POST[ 'editor1' ];

// decode it
$editor_data = html_entity_decode($editor_data);

// set filename
$fileurl = "index2.php";

// write to file
file_put_contents($fileurl, $editor_data);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.