Phpfilesystem file system function usage

Source: Internet
Author: User
Phpfilesystem file system function usage

  1. $ Path = "/home/httpd/phpha.com/index.php ";
  2. Echo basename ($ path );
  3. Echo basename ($ path, '. php ');
  4. Echo basename ($ path, '. xxx ');
  5. Echo dirname ($ path );
  6. ?>
  7. // Result:
  8. Index. php
  9. Index
  10. Index. php
  11. /Home/httpd/phpha.com

Note: If the file name ends with a correct suffix file, this part will be removed. Chgrp-change the group to which the file belongs chown-change the file owner chmod-change the file mode bool chmod (string $ filename, int $ mode)

Example 2:

  1. Chmod ('/home/phpha.txt', 0755 );
  2. ?>

Copy-copy an object

  1. If (copy ('index. php', 'index. php. bak ')){
  2. Echo 'copy success ';
  3. }
  4. ?>
  5. // The index. php. bak file is saved in the current directory.

Delete-see unlink or unset

Unlink-delete file Example 3:

  1. If (unlink ('index. php. bak ')){
  2. Echo 'unlink success ';
  3. }
  4. ?>
  5. // Index. php. bak deleted

Disk_free_space-return the available space disk_total_space in the directory-return the alias of diskfreespace-disk_free_space of the total disk size in a directory

Example 4:

  1. // In Windows:
  2. Echo disk_free_space ("C :"),'
    ';
  3. Echo disk_total_space ("C :");
  4. ?>

// Result: the returned number of bytes is 1743341977632218386432 fopen-open the file or URLfgets-read a row of feof from the file pointer-test whether the file pointer has reached the end of the file fread-read the file (which can be safely used for binary files) fwrite-write a file (which can be safely used for binary files) fclose-close an opened file pointer

Example 5:

  1. $ Fp = fopen('hello.txt ', 'r'); // open a file
  2. $ N = 1;
  3. While (! Feof ($ fp )){
  4. Echo $ n, '-', fgets ($ fp ),'
    '; // Read and output a row
  5. $ N ++;
  6. }
  7. Fclose ($ fp); // close the file
  8. ?>

// Output: 1-Welcome to my blog: 2-http://bbs.it-home.orgfgetc-read character fgetcsv from file pointer-read a line from file pointer and parse CSV field fgetss-read a line from file pointer and filter out HTML tag fputcsv-format row is CSV and writes the file pointer fputs-fwrite alias

  1. $ Fp = fopen('hello.txt ', 'r ');
  2. While (false! ==( $ Char = fgetc ($ fp ))){
  3. Echo $ char ,'-';
  4. }
  5. ?>
  6. // Output:
  7. W-e-l-c-o-m-e--t-o--m-y-B-l-o-g -: ---h-t-p-:-/-B-l-o-g -. -p-h--. -c-o-m-

12. Next page

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.