Log in

View Full Version : saving file using php



shinuthoma
04-01-2009, 04:49 AM
can u tell how i can dynamically save our web page like save as option....

Nile
04-01-2009, 12:01 PM
Like a backup script?

Lpe04
04-01-2009, 02:29 PM
You could use curl and save the text output.

joshuad
04-03-2009, 01:26 AM
I think perhaps what you are looking for is the fwrite() function.

First of course, you'd have to understand the fopen() and flock() functions. Heres an example pulled out of the book, PHP 6 A Beginner's Guide.


<?php
// open and lock file
// write string to file
// unlock and close file
$data = "A fish \n out of \n water\n";
$fp = fopen('output.txt', 'w') or die('ERROR: Cannot open file');
flock($fp, LOCK_EX) or die ('ERROR: Cannot lock file');
fwrite($fp, $data) or die ('ERROR: Cannot write file');
flock($fp, LOCK_UN) or die ('ERROR: Cannot unlock file');
fclose($fp);
echo 'Data written to file';
?>