PHP fopen Create HTML and create directory instances tutorial

Source: Internet
Author: User
Tags create directory mkdir

$path = Date ("y-m-d");
$filename = ' 111cn.net.html ';
$content = ' original www.111cn.net, reproduced annotated original ';
Tohtmlfile ($filename, $content);

function Tohtmlfile ($file _name, $file _content)
{
$dir _name=dirname ($file _name);
Create a directory if it does not exist
if (!file_exists ($dir _name))
{
Mkdirs ($dir _name);
}

if (file_exists ($file _name)) {
@unlink ($file _name); File exists, delete
}

$cjjer _handle = fopen ($file _name, "w+"); Create a file
if (!is_writable ($file _name)) {//Judge Write permission
Exit (' cannot write file ');
}
if (!fwrite ($cjjer _handle, $file _content)) {
Exit (' Write file failed ');
}
Fclose ($cjjer _handle); Close pointer
return $file _name; Return file name
}

Create a directory function

function Mkdirs ($dir)
{
if (!is_dir ($dir)) {
if (!mkdirs (DirName ($dir)) {
Exit (' Cannot create directory ');}
if (!mkdir ($dir, 0777)) {
Exit (' Cannot create directory 2 ');}
}
return true;
}
/*
User Function description
Whether the Is_dir directory is saved
fopen New File
mkdir Create a directory
Fwrite Write files
Fclose closed File
Whether the file_exists file is stored
Unlink Delete Files


More and better manuals http://www.111cn.net/w3school/php/
*/

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.