Page 1 of 1
How can i open an cfg file in an textarea?
Posted: Thu May 22, 2003 5:25 am
by Skywalker
I am having al litle problem, i have created an an cfg file "config" file, in php. I now want to edit it on a website self, that means I have to open it.
When i am opening it, i must see the text in an textarea and when i am finished editing, it must also be saved again.
Can enybody help me with this subject, or at leest give me a push in the write direction?

Posted: Thu May 22, 2003 6:01 am
by Jim
Hehe, funny that you should say the "write" direction...
PHP Manual - FOpen
PHP Manual - FRead
PHP Manual - FWrite
These functions will, in order, open the config file, read the information from the config file, and place the new information you add in to the config file.
Good luck!
Posted: Thu May 22, 2003 11:02 am
by Skywalker
I am having this strange tekst in my textarea? When I am trying to open the file?
This is the strange tekst: Resource id #1
Code: Select all
<?php $handle = fopen ("222.txt","w+");?>
<textarea name="textarea" cols="50" rows="12"><?php echo ($handle); ?></textarea>
Posted: Thu May 22, 2003 11:19 am
by liljester
You have to read from the file handle after you've opened it...
Code: Select all
<?php
$file_name = "222.txt";
$handle = fopen ($file_name,"r");
$whole_file = fread($handle, filesize($file_name));
?>
<textarea name="textarea" cols="50" rows="12"><?php echo ($whole_file); ?></textarea>
Posted: Thu May 22, 2003 2:39 pm
by Skywalker
Ok thx, dat just worked fine for me

New problemo
Posted: Fri May 23, 2003 2:07 am
by Skywalker
If have got a new problem, I now already have a script to open hthe file en write content to it. But when it writes the content to it, it als writes \\\ slashes or dashes wher ever ther are "". so that means my code is not enymore ok when it has been edited. because of the slashes and dashes.
Can somebody help me with this?
Code: Select all
<?php
$filename = $_POST['File'];
$somecontent = $_POST['Content'];
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'ab')) {
print "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}
print "Bestand ge-edit";
fclose($handle);
} else {
print "The file $filename is not writable";
}
?>