HomeSunday, June 24, 2018, 01:45:12
1

PHP Fwrite : fwrite

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

Inserting form data in MySql table

Inserting form data in MySql table with PHP

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.

Preg_Match - PHP Form Validation

PHP form validation with preg_match

Prevent the error loading XML – libxml_use_internal_errors

libxml_use_internal_errors() allows you to disable standard libxml errors and enable user error handling.

E-Cards 1.1. PHP Script

This script will allow your visitors to send e-cards to their friends. It features admin notification and HTML output.To use the "e-cards" script completely free , the "powered by" link at the bottom of the pages must stay intact.

Meta Tags Generator 1.1. PHP Script

This script will allow your visitors to create meta tags online.

PHP $_POST Function

Collect values from a form sent with method post

Bookmark Current Page - PHP Tutorial

Bookmark current page with PHP example.

MySQL to RSS

Publishing MySQL data in RSS

Upload Attachment - PHP Tutorial

Upload attachment with PHP example, Requirement(s): PHP server
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.