How might I write a variable to a file?

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
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

How might I write a variable to a file?

Post by gotDNS »

Say I stick an array of things into a variable....(for DLing a Diary).....how would i write that variable in, oh say, "diary.txt"....

furthermore, how would i have it automatically delete the file after they are done using it?

THANKS!
lc
Forum Contributor
Posts: 188
Joined: Tue Apr 23, 2002 6:45 pm
Location: Netherlands

Post by lc »

Dling a diary? can you explain?

of course you can stick the contents of an array in a textfile and retrieve them later.

For instance I ususally create:

$include = "the array's contents";

then write that in.

but errrr can you explain in more detail? do you want to create a diary script? Or news thing? That's not too hard. I have one at the alienhelpdesk. (called the articler) is that what you need?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

why do you want to write the data to a file and then let the user download it? Why not simply write the contents as plain text? The user may save the file from within the browser.
If you want to emphazise "hey, a file is comming - save it" you may use header informations like
header("Content-Disposition: attachment; filename=diary.txt");
You may also (or as addition) use the gzip functions since (I think) all browsers offer "save file" for application/x-gzip
User avatar
gotDNS
Forum Contributor
Posts: 217
Joined: Tue May 07, 2002 5:53 pm
Location: West Chester, PA

Post by gotDNS »

hey guys...sorry to trouble u all...i got it.....me and my friend figured it out! Thanks for your help, though!

later on, -Brian
Post Reply