Ad block is installed and active. Please support us by disabling it.
HomeSunday, November 19, 2017, 14:11:57
1

PHP Fwrite : fwrite

Monday, February 9, 15, 00:23:49, 3 Yaers Ago Via wain, Hits: 3023
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

PHP Jquery Form

PHP Jquery Form allow your visitors to contact you directly from your website.

MySQL Inner Join

MySQL Inner Join - Creating Dynamic Webpages Using PHP and MySQL, Requirement(s): PHP Server, MySQL

Link Base Pro :: Free Link Index Script

This script allows you to manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links.

Link Base 2.0.

Manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links.

Tell A Friend with Captcha

This form allows your visitors to suggest your site to a friend. It features an HTML email format and an admin notification email.

Preventing multiple form submissions

Preventing multiple form submissions

Smarty - Create dynamic Web Pages with PHP & MySQL

Creating Dynamic Web Pages Using Smarty and MySQL - Requirement(s): PHP Server, MySQL

Upload Image with PHP [Example2]

[Example2] Tutorial - How to upload and resize image with PHP

Captcha V2 - Free PHP Script

PHP Captcha protection image Version 2, - Requirement(s): PHP Server, GD Library

How to set up password for phpMyAdmin in Wamp Server

Password for phpMyAdmin in Wamp
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.