How can i open an cfg file in an textarea?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

How can i open an cfg file in an textarea?

Post 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? :D
Last edited by Skywalker on Thu May 22, 2003 6:12 am, edited 1 time in total.
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post 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!
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post 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>
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post 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>
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post by Skywalker »

Ok thx, dat just worked fine for me ;)
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

New problemo

Post 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"; 
} 
?>
Post Reply