Ad block is installed and active. Please support us by disabling it.
HomeWednesday, April 25, 2018, 08:52:39
1

PHP Fwrite : fwrite

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

Images In Textarea - CSS

Tutorial Images in Textarea

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.

PHP imagecreate

imagecreate() returns an image identifier representing a blank image of specified size.

Imageline

Draws a line between the two given points.

PHP explode

Explode — Split a string by string.

Upload Image With PHP

[Example3] Tutorial - How to upload image in php.

Contact Us Form With Captcha

A contact us form with email and form field validation. It allows your visitors to send you an email directly from your website. Features: Captcha Image, HTML output.

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.

Random MySQL Query

Random MySQL query, requirement(s): PHP Server, MySQL

Bookmark Current Page - PHP Tutorial

Bookmark current page with PHP example.
About Author

wain

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