Forum Moderators: coopster

Message Too Old, No Replies

FTP append?

Can i add text to a file?

         

davejs

4:05 pm on Aug 11, 2004 (gmt 0)

10+ Year Member



Hi

Im using "ftp_put" to copy a file to a new DIR on my server... this works fine...

But.. id like to append some extra text to the end of the file from a variable in php:

$addtext="add this text";

Is this possible, i can see that you can append other files via ftp_put but what about a php string variable?

Many thanks
Dave

dmorison

6:42 am on Aug 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should be able to just fopen() the file with mode "a" (append), and then fwrite() your text out to the file:

---
$addfile = "/path/to/filename"; // the file that you just ftp_put()'ed

$addtext = "add this text;"

$fp = fopen($addfile,"a");

fwrite($fp,$addtext);

fclose($fp);
---

PHP (or rather your webserver) will need write access to the file/directory; but i'm assuming that it has because ftp_put works OK.