SQL PHP HTML ASP JavaScript articles and free scripts to download
 

PHP File Write function

We can write to a file by using fwrite() function PHP. Please note that we have to open the file in write mode and if write permission is there then only we can open it in write mode. If the file does not exist then one new file will be created. We can change the permission of the file also. You can read the content of a file by using fopen() function in PHP. This is the way to write entries to a guestbook, counter and many other scripts if you are not using any database for storing data. . Here we will see how to write to a file.






<?
$body_content="This is my content"; // Store some text to enter inside the file
$file_name="test_file.txt";               // file name
$fp = fopen ($file_name, "w"); 
// Open the file in write mode, if file does not exist then it will be created.
fwrite ($fp,$body_content);          // entering data to the file
fclose ($fp);                                // closing the file pointer
chmod($file_name,0777);           // changing the file permission.
?>

Discuss this tutorial at forum


Further readings
Reading from local and remote files by using fopen()
Writing to a file by fwrite() function
unlink:Deleting file by using unlink function
Deleting all files present inside a directory
Downloading files using header control
File upload to server using PHP
File upload using PHP 5 and register_global off
Uploading More than one file to server
Displaying all files and directory of a folder
Getting the Present file name running the PHP script
Getting the last updated time of the file in PHP
Displaying the last modification time of the file
Searching for text within a pair of tags of a html page
Listing All title tags inside a directory














 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.