Jump to content

[SOLVED] Updating a website in PHP?


noober

Recommended Posts

I'm searching for an easy way for someone who has no idea how to code a website, know html, etc., to log into a page, type in a form, and basically that would be it. The new text would appear on the site and it would be updated. I've seen where you can upload a file to the server with php. I believe it's possible that by doing this would overwrite an existing file, essentially updating the site?

 

Is there a way so that when you submit a form it changes/overwrites information in a file, or the whole file itself. Possibly a .txt?

Link to comment
https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/
Share on other sites

You can do something as basic as this:

<?php
$file = '/home/somebody/the_file.txt';

if(!isset($_POST['content']))
{
$content = file_get_contents($file);
echo <<<EOF
<h1>Edit file '{$file}'</h1>
<form action='{$_SERVER['PHP_SELF']}' method='post'>
<label for='content'>Content:</label><br />
<textarea name='content' id='content'>{$content}</textarea><br />
<input type='submit' value='submit' />
</form>
EOF;
}
else {
if(file_put_contents($file, $_POST['content']))
{
	echo 'The file was updated';
}
else {
	echo 'The file could not be updated';	
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.