Searching...
Sunday 7 October 2012

PHP:What Is Php File

9:24 pm

What Is Php File

PHP:What Is Php File :

Files :
1.      Fopen() : this function is used to open files in php.
2.       
Fopen(string , string);
When the first string argument is name of the file and second string argument is mode of operation.
The mode operations can be either of the following.
r  readonly . starts at the begining of the file.
r +  read/write.
w  write only . opens and clears the contents of file or creates a new file if it doesnot exist.
wread/write.
a  append . opens and writes to the end of the file or creates a new file if it doesnot exist.
a+ read/append.  Presents file content by writing to the end of the file.
x write only. Creates a new file returns FALSE and an error if file already exists.
x+ read/write. Creates a new file . returns false and an error if file already exists.
This function returns a resource of type stream on success and false on failure.
3.      Fclose(file resource) :
                                      This function is used to close and open file.
4.      Feof(file resource):
                                      This function checks if the “end-of-file”(EOF) has been reached. This function return a boolean value. If end-of-file is reached this function returns true otherwise false.
 You cannot read from files opened in w,a and x mode.
5.      Fgets(file resource):
                                      This function is used to read a single line from a file.
6.      Fgetc(file resource):
                                             The function is used to read a single character from a file.
Program to create a file with name india.txt in your application folder.
<?php
//$fp = fopen("india.txt","x");
$fp = fopen("india.txt","w");
var_dump($fp);
if($fp)
{
    echo "file create!!!";
    fclose($fp);
   
}
else
    echo "file is not created!!!";
?>
OutPut:
resource(3) of type (stream) file create!!!
Program to read the data from file line by line or character by character?
<?php
echo "<h1>";
$fp =fopen("india.txt","r") or exit("unable to open file!!!");
while(!feof($fp))
{
    //$str = fgets($fp);
    $str = fgetc($fp);
    echo $str."<br>";
    }
fclose($fp);
?>

php file, open php file, php file upload, what is php file, php file uploader, php file extension, php read file, php file write, php delete file, php open file, php file download, php upload file., 

0 comments:

Post a Comment