Jump to content
xisto Community
Sign in to follow this  
Triple X

Need help... ...again

Recommended Posts

How can I create a php page that lets me edit a file? I mean edit it on the page so i don't have to go into cpanel to do it, I wanna do it so I can edit my "news" file from a page(which i will duh p/w protect).Any help would be awesome.

Edited by Triple X (see edit history)

Share this post


Link to post
Share on other sites

What kind of data management application are you using to run your website?Im not very sure what you mean, but if you using any php data management application, maybe make a news module with admin permission to change and users to view only. I believe they already have news module out there for most applications like php-nuke, mambo, dotnetnuke. And all you have to do is go to admin back-end and write whatever you want in news section and select who could view and edit the file.

Share this post


Link to post
Share on other sites

You could use something like this:

<?php[br][/br]$newsfile = "news-file";[br]// Assuming you are using a flat-file to store your news,[/br]// replace 'news-file' with the path to it[br][/br]if(!isset($_GET['act'])) {[br]  $act = "view";[/br]} else {[br]  $act = $_GET['act'];[/br]}[br][/br]if(isset($_POST['news'])) {[br]  $file = fopen($newsfile,"w");[/br]  $data = $_POST['news'];[br]  fputs($file,$data);[/br]  fclose($file);[br]  echo "News saved.";[/br]  exit;[br]}[/br]  [br][/br]if($act == "edit") {[br]  $data = file_get_contents($newsfile);[/br]  echo "<form name=\"editnews\" method=\"post\" action=\"script.php\">\n";[br]  echo "<textarea name=\"news\">" . $data . "</textarea>\n";[/br]  echo "<input type=\"submit\" name=\"save-news\" value=\"Save\"></form>";[br]} elseif($act == "view") {[br]  $data = file_get_contents($newsfile);[/br]  echo $newsfile;[/br]}[br][/br]?>

Note that I just threw this script together for the sake of this post, and haven't tested it yet. Feel free to use / edit it as you wish.

Share this post


Link to post
Share on other sites

One: what is a "flat file" like only test or w/e? if so then yes I am using one.It didn't work....I copyed the code saved it and all the page had was the filename, nothing else no textarea no nothing sept the filename...thanks anyway.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.