Php file creation instance code

Source: Internet
Author: User
Php file creation code: & lt ;? Php $ datadate (Ymd); $ dir/hom/kyle/file/$ data; $ filename/home/kyle/file/$ data/testfile; $ filecontent: this is the content to be written. test the space. // You can check whether a folder exists. otherwise, create if (! Is_dir ($ dir explains the code for creating a file instance in php:

  1. $ Data = date ("Ymd ");
  2. $ Dir = "/hom/kyle/file/$ data ";
  3. $ Filename = "/home/kyle/file/$ data/testfile ";
  4. $ Filecontent = "this is the content to be written test space ";
  5. // Determine whether the folder exists; otherwise, create
  6. If (! Is_dir ($ dir )){
  7. Mkdir ($ dir, 0777 );
  8. }
  9. // Determine whether the file exists; otherwise, create
  10. If (! File_exists ($ filename) {$ handle = fopen ($ filename, w );
  11. If (! $ Handle ){
  12. Echo create file fail;
  13. Exit;
  14. } Else {
  15. Chmod ($ filename, 0777 );
  16. }
  17. If (fwrite ($ handle, $ filecontent) === FALSE ){
  18. Echo "cant write into $ filename ";
  19. Exit;
  20. }
  21. Fclose ($ handle );
  22. }
  23. ?>

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.