Ad block is installed and active. Please support us by disabling it.
HomeSaturday, January 20, 2018, 16:55:23
1

PHP Fwrite : fwrite

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

Contact Us 2.0. with HTML Page and Pop Up Frame

This is the same Contact Us 2.0. that is in this forum, But I have added more options to this script and a html page with a very nice pop Up frame that DONT get block by any pop Up software. Many websites use this type of script to bypass the blocking…

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

Addslashes - Stripslashes

addslashes — quote string with slashes, stripslashes — un-quotes a quoted string

PHP $_GET Function

Get function in PHP

PHP form with image upload

Advanced Contact Form with email and form field validation.It allows your visitors to send you an email directly from your website.Features: Image Upload, HTML Output, Captcha Image.

PHP $_SESSION

Session_start creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

Bookmark Current Page - PHP Tutorial

Bookmark current page with PHP example.

Upload File with PHP

Basic file uploading with PHP

Creating a Math CAPTCHA with PHP - PHP Tutorial

This tutorial will show you how to create a form with Math Captcha.
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.