noober Posted January 19, 2008 Share Posted January 19, 2008 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? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted January 19, 2008 Share Posted January 19, 2008 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'; } } ?> Quote Link to comment Share on other sites More sharing options...
noober Posted January 19, 2008 Author Share Posted January 19, 2008 Wow. I was expecting a yes or no, maybe a link to somewhere, but actual code?! I haven't seen if it works, but I can't thank you enough. Quote Link to comment Share on other sites More sharing options...
noober Posted January 20, 2008 Author Share Posted January 20, 2008 Hmm. I seem to be getting this error. Any ideas? Fatal error: Call to undefined function: file_put_contents() in /homepages/15/d223291516/htdocs/main/download.php on line 25 Quote Link to comment Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 What version of PHP do you have? Quote Link to comment Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Have a look at php.net/fwrite Quote Link to comment Share on other sites More sharing options...
noober Posted January 20, 2008 Author Share Posted January 20, 2008 I'll check what version I have....but it was referring to this line. if(file_put_contents($file, $_POST['content'])) Quote Link to comment Share on other sites More sharing options...
noober Posted January 20, 2008 Author Share Posted January 20, 2008 I feel so noobish! I'm assuming my hosting server sets what version of php I use? Am I correct in thinking this? I'm in xhtml1.0 transitional. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 Create a new php file and just put <?php phpinfo(); ?> You'll get the version there. I think the function in the above code is only in PHP5. Quote Link to comment Share on other sites More sharing options...
noober Posted January 20, 2008 Author Share Posted January 20, 2008 Ah, yes, I managed to find the code to see what php version I'm running. It's 4.47, so that would explain why it didn't work, I suppose. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 Find out if you host offers PHP5 Quote Link to comment Share on other sites More sharing options...
noober Posted January 20, 2008 Author Share Posted January 20, 2008 OK. Eyep. My host defaults it to 4, but they have a work around to make it 5 if it is desired. Thanks eveyrone. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.