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? Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/ 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'; } } ?> Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-443427 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. Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-443850 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 Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444045 Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 What version of PHP do you have? Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444047 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 Have a look at php.net/fwrite Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444052 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'])) Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444058 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. Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444064 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. Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444067 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. Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444071 Share on other sites More sharing options...
revraz Posted January 20, 2008 Share Posted January 20, 2008 Find out if you host offers PHP5 Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444075 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. Link to comment https://forums.phpfreaks.com/topic/86758-solved-updating-a-website-in-php/#findComment-444082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.