Ad block is installed and active. Please support us by disabling it.
HomeThursday, September 21, 2017, 03:22:35
1

PHP Fwrite : fwrite

Monday, February 9, 15, 00:23:49, 3 Yaers Ago Via wain, Hits: 2702
php write to file - how to write data to a file using the php frwite function
Example 1
Code:
<?php
$file = "text.txt";
@$fh = fopen($file, 'w') or die("can't open file");
$data = "PHP is an open-source server-side scripting language.";
fwrite($fh, $data);
fclose($fh);
echo "OK";
?>


Example 2
Code:
<?php
if(isset($_POST['submit']))
{
$file = "config.php";
@$fh = fopen($file, 'w') or die("can't open file");
$host = $_POST['localhost'];
$name = $_POST['dbname'];
$user = $_POST['dbuser'];
$pass = $_POST['dbpass'];
$data = "<?php
\$localhost='$host';
\$dbname='$name';
\$dbuser='$user';
\$dbpass='$pass';
?>";
fwrite($fh, $data);
fclose($fh);
echo "OK";
}else{
?>
<form action="index.php" method="POST">
localhost:<input type=text name="localhost"<br>
dbname:<input type=text name="dbname"<br>
dbuser:<input type=text name="dbuser"<br>
dbpass:<input type=text name="dbpass"<br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
}
?>

Sign In

Sponsor

Related

Convert pdf to image - mpdf

Convert pdf file to jpg with php and mpdf

PHP filesize

The filesize function returns the size of the specified file.

MySQL to RSS

Publishing MySQL data in RSS

Link Generator PHP Script

This script will allow your visitors to create links online.To use the "link generator" script completely free , the "powered by" link at the bottom of the pages must stay intact.

Password Protect With PHP

Password protect tith PHP - tutorial

PHP $_POST Function

Collect values from a form sent with method post

Creating a basic bad word filter in PHP

This tutorial will show you how to create a basic bad word filter in PHP

Upload File with PHP

Basic file uploading with PHP

PHP Cookies - setcookie

Defines a cookie to be sent along with the rest of the HTTP headers.

PHP highlight_string - PHP Tutorial

Outputs or returns a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax highlighter for PHP. Requirement(s): PHP Server.
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Thu, Jun 15, 17
So far has created 115 entries.
wain
This author has not yet filled in any details.