Forum Moderators: coopster

Message Too Old, No Replies

editing a file

Cant seem to open/edit

         

nfs2

10:14 am on May 17, 2006 (gmt 0)

10+ Year Member



Trying to open a file so its contents display in a textarea, so i can edit it.

<?php
$file = 'templates/journals/layout.tpl';
$body = fopen($file, 'a') or die("can't open file");
?>
<textarea style="width: 800px; height: 600px"><?php $body;?></textarea>

This doenst work. Using echo doesnt work either. Does anyone know how to do this?

ahmedtheking

10:25 am on May 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

<?php
$myfile = implode("",file("path/to/file.txt"));
?>

<textarea ... ><?=$myfile;?></textarea>

dreamcatcher

10:42 am on May 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or use file_get_contents:

$body = file_get_contents($file);

echo $body;

dc

nfs2

10:59 am on May 17, 2006 (gmt 0)

10+ Year Member



Thanks for the help guys, the first one worked great.

Im sure the 2nd suggestion would work too, but i havent tried it. Thanks to both of you anyways.

jatar_k

4:04 pm on May 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the fopen didn't work because all that returns is a file pointer

you would need to use that file pointer and then use fread or similar to get the actual data from the file