PHP fopen function Usage (open create file) _php Tutorial

Source: Internet
Author: User
PHP Tutorial fopen function Usage (open create file)
In a lot of time we need to create a file, especially to generate static page time, we often use in PHP fopen this function to create a new file, its original is how the file exists on the append, does not exist can be created, there are a lot of parameters, with you according to your needs to define parameters.
$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 adds success ';
}
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");


/*
Detailed description of the fopen function

Definition and usage
The fopen () function opens the file or URL.

If open fails, this function returns FALSE.

Grammar
fopen (filename,mode,include_path,context) parameter description
FileName is required. Specifies the file or URL to open.
Mode required. Specifies the type of access required to the file/stream. The possible values are shown in the following table.
Include_path is optional. If you also need to retrieve the file in Include_path, you can set the parameter to 1 or true.
The context is optional. Rules


The "R" read-only mode opens, pointing the file pointer to the file header.
The "r+" read-write mode opens, pointing the file pointer to the file header.
The "W" Write method opens, pointing the file pointer to the file header and truncating the file size to zero. Create.
The "w+" read-write mode opens, pointing the file pointer to the file header and truncating the file size to zero. Create.
The "A" write opens, pointing the file pointer to the end of the file. The file does not exist for creation.
A + read-write mode opens, pointing the file pointer to the end of the file. The file does not exist for creation.

*/
?>


http://www.bkjia.com/PHPjc/445397.html www.bkjia.com true http://www.bkjia.com/PHPjc/445397.html techarticle PHP Tutorial fopen function Usage (open create file) in a lot of time we need to create files, especially when generating static pages, we often use in PHP fopen this function to ...

  • Related Article

    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.