Monday, November 4, 2013

FIle Handling in PHP (File Reading and Writing)

Hiiiii, we always find it difficult to work with files in our early stages of programming in any language. But sometimes it is necessary to work with files when it comes to reading and writing text files, doc files or html files. So, in this tutorial I am providing you a very simple code for file handling. It is easy to understand and execute. I have tested this code with text files and html files but you can try it with different format files also like doc, etc.

FIle Handling in PHP

CODE BEGINS :

<?php

$read_file=getcwd()."/b.txt";
$dir=getcwd();
$file = fopen($read_file, "r");
$file_contents=array();
echo $file_contents = file_get_contents($read_file);
fclose($file);
echo $write_file=getcwd()."/c.txt";

while ($file_contents)
{
$fle1 = fopen($write_file,'w') or die("Could not find file");
fwrite($fle1,$file_contents);
}

?>


Hope you like this post……..Please Comment…………!!!!!!!!!


Tags:

0 Responses to “FIle Handling in PHP (File Reading and Writing)”

Post a Comment

© 2013 MyCodeStock. All rights reserved.
Designed by SpicyTricks