PHP Saving 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
reyes99
Forum Commoner
Posts: 38
Joined: Tue May 22, 2007 10:35 pm

PHP Saving to a File

Post by reyes99 »

Hi Everyone,

I am new to PHP..

I created a form that I would like to save to a file like a .txt files or .csv file.

Is this possible with PHP?? If so how?? I tried searching google but did not find anything.

Thanks

Ralph
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

Yes, take a look in the manual at some of the file functions. Start with fopen().

If you want to avoid the headache of storing data in flatfiles, you might consider working with SQLite or MySQL. Depending on your specific application, of course.
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

Perform this:

Code: Select all

$file .= "";
$file .= "<?php";
$file .= "//php contents goes here.. ";
$file .= "?>";

$fs = @fopen("$savepath/" . $filename . '.php', 'w+t');
@fwrite($fs, $file);
@fclose($fs);
Hope this may help You
reyes99
Forum Commoner
Posts: 38
Joined: Tue May 22, 2007 10:35 pm

Post by reyes99 »

Thank you guys...

I will try that

Ralph
Post Reply