Menu
Is there a way/script that can allow me to edit the content of a page (very simple, just a text box that shows the code) and save/submit it without using a database?
In PHP of course.
<?php
if (isset($_POST["content"]))
{
//the following will be processed if the content feild has something set to it
$content = $_POST["content"];
$file = $_POST["location"];
$open = fopen($file, "w+");
$write = fwrite($open,$content);
<i> </i> $write;
//checks if the file has been edited:
if ($write == true)
{
echo "File editted sucessfully!";
}
//If the file has had a problem being written to, the follwing is run:
else
{
echo "There was a problem, please try again. Problems may include that you did not make any changes to the file.";
}
<i> </i> fclose($open);
<i> </i> }
//the following will be processed if the content feild does NOT have anyting set to it
else
{
echo "No file has been selected to edit.";
}
?>
<?php
if (isset($_POST["submit"]))
{
if ($_POST["filename"] == "")
{
echo "Please enter a file name";
}
else
{
if (file_exists($_POST["filename"]) == false)
{
echo "This file does not exist";
}
else {
<i> </i> $filename = $_POST["filename"];
<i> </i> echo "<form action="editfile.php" method="post">
<i> </i> <textarea name="content" cols="100" rows="30">". file_get_contents($filename) ."</textarea>
<i> </i> <input name="location" type="hidden" value="". $filename ."" /><br><br>
<i> </i> <input name="submit" type="submit" value="Make Changes to the file"/>
<i> </i> </form>";
<i> </i> }
<i> </i> }
<i> </i> }
else
{
echo "<form action="". $_SERVER["PHP_SELF"]. "" method="post">
Enter the file location you want to edit:<input name="filename" type="text" /><br /><br />
<input name="submit" type="submit" value="Click here to edit" />
</form>";
}
?>
^^
We've got Sherlock on the case.
It was only meant for personal use. Calm down.
What do you expect me to do, write a bullet-proof script for someone i dont even know and not get paid?
I provided an outline to the script that is required, it is up to the OP to secure it depending on the environment they wish to run it on.
Would you prefer me to remove it completely and therefore not offer any help to the OP?
or guide the OP the best I can with the short time I had?
By the way, those are rhetorical questions.[/QUOTE]
[CODE]<script type=\\\"text/javascript\\\">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval(\\\"page\\\" + id + \\\" = window.open(URL, \\\'\\\" + id + \\\"\\\', \\\'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=700,left = 326,top = 0\\\');\\\");
}
</script>
<a href="javascript:popUp('documents/tscf.jpg')"><img src="documents/tscf.gif" border="0"/></a>
<a href="javascript:popUp('documents/tscb.jpg')"><img src="documents/tscb.gif" border="0"/></a>
<script type=\\\"text/javascript\\\">
var speed, currentpos=curpos1=0,alt=1,curpos2=-1
function initialize(){
if (window.parent.scrollspeed!=0){
speed=window.parent.scrollspeed
scrollwindow()
}
}
function scrollwindow(){
temp=(document.all)? document.body.scrollTop : window.pageYOffset
alt=(alt==0)? 1 : 0
if (alt==0)
curpos1=temp
else
curpos2=temp
window.scrollBy(0,speed)
}
setInterval(\\\"initialize()\\\",10)
</script>[/CODE]
^^
We've got Sherlock on the case.
It was only meant for personal use. Calm down.
What do you expect me to do, write a bullet-proof script for someone i dont even know and not get paid?
I provided an outline to the script that is required, it is up to the OP to secure it depending on the environment they wish to run it on.
Would you prefer me to remove it completely and therefore not offer any help to the OP?
or guide the OP the best I can with the short time I had?
By the way, those are rhetorical questions.[/QUOTE]
I feel that you have taken the points I raised above to seriously.
I was merely stating that the code should be reviewed before use due to its nature. As you agree the code above is not bullet proof I do not see why my post seems to have enraged you.
Elementary my dear Watson.
Also the reason it is adding the "" is due to your server usingmagic_quotes . To address this issue you could disable them or usestripslashes() on all instances of $_POST values.[/QUOTE]
<?php
if (isset($_POST["content"]))
{
//the following will be processed if the content feild has something set to it
$content = stripslashes($_POST["content"]);
$file = stripslashes($_POST["location"]);
$open = fopen($file, "w+");
$write = fwrite($open,$content);
<i> </i> $write;
//checks if the file has been edited:
if ($write == true)
{
echo "File editted sucessfully!";
}
//If the file has had a problem being written to, the follwing is run:
else
{
echo "There was a problem, please try again. Problems may include that you did not make any changes to the file.";
}
<i> </i> fclose($open);
<i> </i> }
//the following will be processed if the content feild does NOT have anyting set to it
else
{
echo "No file has been selected to edit.";
}
?>
0.1.9 — BETA 5.19