Php: how to create a file instance code-PHP source code

Source: Internet
Author: User
Fopen is used to create files in php, and \ w \ or \ w + "is used to create files, the fopen function requires two important information blocks to run normally. First, we must provide the file. We want it to open it and name it. Second, we must tell us what functions we need to plan to create files with this file. fopen will be used to create files in php, it will be created using \ "w \" or \ "w +, the fopen function requires two important information blocks to run normally. First, we must provide the file. We want it to open it and name it. Second, we must tell us what features to plan with this file

Script ec (2); script

*/

The Code is as follows:
$ Fn = 'www.111cn.net.txt'
$ Fcon = 'php how to create a file'; // content
If ($ f = fopen ($ fn, "w "))
{
If (fwrite ($ f, $ fcon ))
{
Echo 'file written successfully ';
}
Else
{
Echo 'file not write ';
}
Fclose ($ f );
}
Else
{
Echo 'The file cannot be created. Check the authorization ';
}


/*
$ Fn = 'www.111cn.net.txt '; create a file name

Open the "w" Write mode, point the file pointer to the file header, and cut the file size to zero. If the file does not exist, try to create it.
Open in "w +" read/write mode, point the file pointer to the file header, and cut the file size to zero. If the file does not exist, try to create it.
Fclose ($ r) // close the opened file. The file handle required for fclose is closed.
The original tutorial on this site is reproduced with the source www.111cn.net
*/

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.