Php fopen function usage (open the file creation)

Source: Internet
Author: User

 

Php tutorial fopen function usage (open a file)
In many times, we need to create files, especially when generating static pages. in php, we often use the fopen function to create files. It is used to append files when files exist, you can create a parameter if it does not exist. Many parameters are provided below. You can define parameters as needed.
$ Xxx = fopen ("text.txt", 'w', ture)

*/
$ Fopen = 'fopen.txt ';
$ Str = 'write a file www.bkjia.com ';
If (file_exists ($ fopen ))
{
$ H = fopen ($ fopen, 'a + ');
If (fwrite ($ h, $ str ))
{
Echo 'content added successfully ';
}
Fclose ();
}
Else
{
$ H = fopen ($ fopen, 'W + ');
If (fwrite ($ h, $ str ))
{
Echo 'file written successfully ';
}
Fclose ();
}

$ File = fopen ("test.txt", "r ");
$ File = fopen ("/home/mb.php100.com/test.txt", "r ");
$ File = fopen ("/home/test/test.gif", "wb ");
$ File = fopen ("http://www.bkjia.com/", "r ");
$ File = fopen ("ftp: // user: password@example.com/test.txt", "w ");


/*
Fopen function details

Definition and usage
The fopen () function opens a file or url.

If opening fails, this function returns false.

Syntax
Fopen (filename, mode, include_path, context) parameter description
Filename is required. Specifies the file or url to open.
Mode is required. Specifies the access type of the file/stream. Possible values are shown in the table below.
Optional. If you also need to retrieve the file in include_path, you can set this parameter to 1 or true.
Context is optional. Rules


Open the file in read-only mode and point the file pointer to the file header.
Open the "r +" read/write mode and point the file pointer to the file header.
Open the "w" Write mode, point the file pointer to the file header, and cut the file size to zero. Create.
Open in "w +" read/write mode, point the file pointer to the file header, and cut the file size to zero. Create.
"A" is opened in writing mode, pointing the file pointer to the end of the file. The file does not exist.
Open the "a +" read/write mode and point the file pointer to the end of the file. The file does not exist.

*/
?>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.