Introduction to PHP File system function collation

Source: Internet
Author: User
Tags chmod filegroup http post php file php and symlink


Introduction: This is the introduction of PHP and file operations related to the system functions, these functions are also very important, the following tianya is still more commonly used for detailed illustrations.

basename-returns the file name part of the path
dirname-returns the directory part of the path

String basename (String $path [, String $suffix])
String DirName (String $path)

Example:

The code is as follows Copy Code
<?php
Tianya PHP Blog Http://www.111cn.net
$path = "/home/httpd/www.111cn.net/index.php";
Echo basename ($path);
Echo basename ($path, '. php ');
Echo basename ($path, '. xxx ');
echo dirname ($path);
?>
Results:
index.php
Index
index.php
/home/httpd/www.111cn.net

Description: If the filename is ended with the correct suffix, this part will also be removed.

chgrp-change the group to which the file belongs
chown-change the owner of the file
chmod-Change File Mode

BOOL Chmod (string $filename, int $mode)

Example:

The code is as follows Copy Code
<?php
chmod ('/home/phpha.txt ', 0755);
?>

copy-Copy Files

The code is as follows Copy Code
if (copy (' index.php ', ' Index.php.bak ')) {
echo ' Copy success ';
}
?>

Index.php.bak files exist in the current directory

delete-See unlink or unset
unlink-Delete Files

The code is as follows Copy Code

<?php
if (unlink (' Index.php.bak ')) {
Echo ' unlink success ';
}
?>
Removed the Index.php.bak

disk_free_space-returns the available space in the catalog
disk_total_space-returns the total disk size of a directory
Alias of Diskfreespace-disk_free_space

The code is as follows Copy Code
<?php
Under Windows:
Echo Disk_free_space ("C:"), ' <br/> ';
Echo Disk_total_space ("C:");
?>
Result: The number of bytes returned
17433419776
32218386432

fopen-open a file or URL
Fgets-reads a row from the file pointer
feof-the test file pointer to the end of the file
fread-read files (can be used securely in binary files)
fwrite-Write to file (safe for binary files)
fclose-closes an open file pointer

  code is as follows copy code
<?php
   //Tianya PHP blog http://www.111cn.net
    $fp = fopen (' hello.txt ', ' r ');//Open a file
& nbsp;   $n = 1;
    while (!feof ($fp)) {
    echo $n, '-', fgets ($fp), ' <br/> ';//read a row and output
    $n + +;
   }
    fclose ($FP);//close file
   
   //output:
     1-welcome to my blog:
    2-http://www.111cn.net

Fgetc-reads characters from the file pointer
Fgetcsv-reads a line from the file pointer and resolves the CSV field
Fgetss-reads a row from the file pointer and filters out the HTML markup
fputcsv-the row into CSV and writes the file pointer
Alias of Fputs-fwrite

The code is as follows Copy Code
<?php
$fp = fopen (' hello.txt ', ' R ');
while (false!== ($char = fgetc ($fp))) {
Echo $char, '-';
}
?>
Output:
w-e-l-c-o-m-e--t-o--m-y--b-l-o-g-:---h-t-t-p-:-/-/-b-l-o-g-.-p-h-p-h-a-.-c-o-m-

file_exists-check whether a file or directory exists

The code is as follows Copy Code
<?php
if (file_exists (' Hello.txt ')) {
Echo ' hello.txt exists ';
}else{
Echo ' hello.txt not exists ';
}
?>
Output:
Hello.txt exists

file_get_contents-reads the entire file into a string
File_put_contents-writes a string to a file
File-reads the entire file into an array

  code is as follows copy code
<?php
    if ($content = file_get_contents (' hello.txt ')) {
    file_put_contents (' Hello.txt.bak ', $content);
   }
   
   //equivalent to copy a copy of Hello.txt
    <?php
     if ($content = file (' hello.txt ')) {
    print_r ($content);
   }
   
   //Array form, each row is an array member
    array
     (
    [0] => Welcome to my blog:
    [1] => http://www.111cn.net
&N bsp;  )

Fileatime-last access time for files
Filectime-Gets the Inode modification time of the file
filegroup-the group that gets the file
Fileinode-get the inode of the file
filemtime-Get File modification time
Fileowner-gets the owner of the file
fileperms-permission to obtain files
filesize-Get File size
filetype-Get file type

The code is as follows Copy Code
<?php
    echo fileatime (' hello.txt ');
    Echo filectime (' hello.txt ');
    echo Filegroup (' hello.txt ');
    Echo filemtime (' hello.txt ');
    Echo fileowner (' hello.txt ');
    Echo substr (sprintf ('%o ', fileperms (' Hello.txt ')),-4);
    echo filesize (' hello.txt ');
    echo filetype (' hello.txt ');
   
   /output:
    1353329003
    1353329003
    0
    1353330002
    0
    0666
   
    file

flock-Lightweight Consultation File lock
fnmatch-match filename with pattern
fflush-output The buffered content to a file
fpassthru-all remaining data at the output file pointer
fscanf-format input from a file
fseek-position in file pointer
fstat-access to file information through an open file pointer
ftell-returns the location of the file pointer read/write
ftruncate-the file to a given length
glob-find a file path that matches the pattern

is_dir-determine if a given file name is a directory
is_executable-to determine if a given file name is executable
is_file-to determine if a given file name is a normal file
is_link-determines whether a given file name is a symbolic connection
is_readable-to determine if a given file name is readable
is_uploaded_file-to determine if the file was uploaded via an HTTP POST
is_writable-to determine if a given filename is writable
Alias of Is_writeable-is_writable
Description: The above functions are used to determine whether a file or directory meets the corresponding conditions, return TRUE or false.

Lchgrp-changes Group Ownership of Symlink
Lchown-changes user ownership of Symlink
link-Establish a hard connection
Linkinfo-to get a connection information
Lstat-gives information about a file or symbolic connection
mkdir-New Directory
Move_uploaded_file-move uploaded files to a new location
parse_ini_file-resolves a configuration file
pathinfo-returns the file path information
pclose-shutdown Process file pointer
popen-Open Process file pointer
readfile-output a file
readlink-returns the target to which the symbolic connection points
realpath-returns the canonical absolute path name
rename-rename a file or directory
Rewind-back to the location of the file pointer
rmdir-Delete Directory
Alias of Set_file_buffer-stream_set_write_buffer
stat-gives the file information
symlink-to establish a symbolic connection
tempnam-to create a file with a unique file name
tmpfile-Create a temporary file
touch-settings file access and modification time
umask-Change the current umask
clearstatcache-Purge file state cache

Summary: In fact, so many file manipulation functions, most of which can not be used, but also see how these functions and the Linux command similar to the size of the

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.