Jump to content

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';	
}
}
?>

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.