Jump to content

Change value in php code?


evAN-_^

Recommended Posts

Okay here I go, I'm terrible with PHP so bare with me. What I'm wanting to do is create a small, very basic file editing system, now here's my problem. I have the following files;

 

Contents of, form.php

<form action="processscript.php" method="post">
<textarea rows="25" cols="40" name="content">
<? $fn = "test.txt"; print htmlspecialchars(implode("",file($fn))); ?> 
</textarea>
<input type="submit" value="Change!"> 
</form>

 

Contents of, processscript.php

<?
$fn = "test.txt";
$content = stripslashes($_POST['content']);
$fp = fopen($fn,"w") or die ("There was an error in opening the modified file.");
fputs($fp,$content);
fclose($fp) or die ("There was an error in closing the modified file.");
echo "You've successfully updated $fn, you'll be redirected in 3 seconds...";
?>
<meta HTTP-EQUIV="REFRESH" content="3; url=test.txt">

 

Now, obviously those two files together update the 'test.txt' file, right? Well, Above the text box in 'form.php' I want to add a jump down menu, which is easy done in Dreamweaver - like so;

 

jumpdownmk6.jpg

 

Now, what I want to do (which I cannot figure out how to do...) is that when you click one of the values on the jump down menu, for example we'll say Option 2, I'd like the value of $fn (which is test.txt) to change to another file, basically I want to be able to use this drop down file to edit multiple pages. I hope I've explained this clearly, I really need some help, cheers!

 

 

Link to comment
https://forums.phpfreaks.com/topic/104742-change-value-in-php-code/
Share on other sites

From what I under stand, you want that drop down list to contain the other files that you'd like to edit?

What you'll need to do is write a script that lists the files of a given directory. Something like:

<?php
$Location = ".";
$OptionsList = "";
if( $Handle = opendir($Location) ) {
	while( ($FFName = readdir($Handle)) !== false ) {
		$OptionsList .= "<option value='$FFName'>$FFName</option>";
	}
}
closedir($Handle);
?>

For this script, you'll probably want to save your text files in their own folder.

$Location = "./textfiles";

 

This creates the Option List in the Select Form. To show the list is easy:

<select name="myfiles">
<?=$OptionsList; ?>
</scelect>

 

You'll need a javascript code that will automatically submit once you select your file. I'm not 100% sure of the function as I don't do javascript too often.

 

Also I'd add this dropdown in it's own form so that once the submit command is passed you don't save any unwanted changes to the text document.

 

Just replace the $fn with "./textfiles/". $_POST[myFiles] (or however you'd like to set it up)

Agreed. There are three types of website makers;

 

- the designers (they use dreamweaver/fireworks etc) to design their page, and let some software code it for them (lazy buggers)

- the coders - they use web editors/text editors, sometimes with autofillers (they pwn)

- the n00bs that use freewebs. They suck.

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.