Php read, delete, and write file instance tutorial-PHP source code

Source: Internet
Author: User
Ec (2); php read, delete, Write File instance tutorial --------------------------------- delete file functionDelFiletext ($ filename) {& nbsp; @ unlink ($ filename );} --------------------------------- obtain the file content functionReadFiletext ($ filepa script ec (2); script

Php example of reading, deleting, and writing files

// --------------------------------- Delete an object
Function DelFiletext ($ filename ){
@ Unlink ($ filename );
}

// ----------------------------------- Obtain the File Content
Function ReadFiletext ($ filepath ){
$ Htmlfp = @ fopen ($ filepath, "r ");
While ($ data = @ fread ($ HTML, 1000 ))
{
$ String. = $ data;
}
@ Fclose ($ htmlfp );
Return $ string;
}

// ---------------------------------- Write a file
Function WriteFiletext ($ filepath, $ string ){
Global $ filechmod;
$ String = stripSlashes ($ string );
$ Fp = @ fopen ($ filepath, "w ");
@ Fputs ($ fp, $ string );
@ Fclose ($ fp );
If (empty ($ filechmod ))
{
@ Chmod ($ filepath, 0777 );
}
}

// ---------------------------------- Write a file
Function WriteFiletext_n ($ filepath, $ string ){
Global $ filechmod;
$ Fp = @ fopen ($ filepath, "w ");
@ Fputs ($ fp, $ string );
@ Fclose ($ fp );
If (empty ($ filechmod ))
{
@ Chmod ($ filepath, 0777 );
}
}

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.