Introduction to FileSystem File system functions in PHP and examples of using _php tutorials

Source: Internet
Author: User
Tags aliases filegroup rewind symlink
basename-returns the file name portion of the path
dirname-returns the directory portion of the path

Copy the Code code as follows:
String basename (String $path [, String $suffix])
String DirName (String $path)

Example:
Copy the Code code as follows:
$path = "/home/httpd/phpha.com/index.php";
Echo basename ($path);
Echo basename ($path, '. php ');
Echo basename ($path, '. xxx ');
echo dirname ($path);
?>

Copy the Code code as follows:
Results:
index.php
Index
index.php
/home/httpd/phpha.com

Note: If the file name ends with the correct suffix, then this part will be removed as well.

chgrp-changing the group to which the file belongs
chown-changing the owner of a file
chmod-changing the file mode

Copy the Code code as follows:
BOOL Chmod (string $filename, int $mode)

Example:

Copy the Code code as follows:
chmod ('/home/phpha.txt ', 0755);
?>
copy-Copy Files

if (copy (' index.php ', ' Index.php.bak ')) {
echo ' Copy success ';
}
?>
Index.php.bak file survived in current directory

delete-See unlink or unset
unlink-Deleting files

Copy the Code code as follows:
if (unlink (' Index.php.bak ')) {
Echo ' unlink success ';
}
?>
Removed the Index.php.bak

disk_free_space-returns the free space in the directory
disk_total_space-returns the total disk size of a directory
Aliases for Diskfreespace-disk_free_space

Copy the Code code as follows:
Under Windows:
Echo Disk_free_space ("C:"), '
';
Echo Disk_total_space ("C:");
?>

Copy the Code code as follows:
Result: The number of bytes returned
17433419776
32218386432

fopen-Open File or URL
fgets-reading a line from the file pointer
feof-Test If the file pointer is at the end of the file
fread-read files (can be used safely in binary files)
fwrite-writing files (can be used safely in binary files)
fclose-Close an open file pointer

Copy the Code code as follows:
$fp = fopen (' hello.txt ', ' R '); Open a file
$n = 1;
while (!feof ($fp)) {
Echo $n, '-', fgets ($fp), '
'; Reads a row and outputs
$n + +;
}
Fclose ($FP); Close File
?>

Copy the Code code as follows:
Output:
1-welcome to my blog:
2-http://www.jb51.net

fgetc-reading characters from the file pointer
Fgetcsv-reads a row from the file pointer and resolves the CSV field
Fgetss-reads a row from the file pointer and filters out HTML tags
fputcsv-format the row as CSV and write the file pointer
Aliases for Fputs-fwrite

Copy the Code code as follows:
$fp = fopen (' hello.txt ', ' R ');
while (false!== ($char = fgetc ($fp))) {
Echo $char, '-';
}
?>

Copy the Code code as follows:
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-checking whether a file or directory exists

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

[/code]
Output:
Hello.txt exists
[/code]

file_get_contents-to read the entire file into a string
file_put_contents-writing a string to a file
file-to read an entire file into an array

Copy the Code code as follows:
if ($content = file_get_contents (' hello.txt ')) {
File_put_contents (' Hello.txt.bak ', $content);
}
?>
Equivalent to copy a copy of a hello.txt
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.jb51.net
)

Fileatime-last access time of the file
filectime-Get the Inode modification time of the file
filegroup-get the group of files
fileinode-obtaining the Inode of the file
filemtime-Get File modification time
Fileowner-get the owner of the file
fileperms-permission to obtain a file
filesize-Get File size
filetype-getting the file type

Copy the Code code as follows:
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 ');
?>

Copy the Code code as follows:
Output:
1353329003
1353329003
0
1353330002
0
0666
42
File

flock-Lightweight consultation document lock-up
fnmatch-matching file name with pattern
fflush-output buffered content to a file
fpassthru-all remaining data at the output file pointer
fscanf-formatting input from a file
fseek-positioning in the file pointer
fstat-obtaining file information from an open file pointer
ftell-returns the position of the file pointer read/write
ftruncate-truncates a file to a given length
glob-looking for file paths that match the pattern

is_dir-determines whether a given file name is a directory
is_executable-to determine if the given file name is executable
is_file-determine if the given file name is a normal file
is_link-determines whether a given file name is a symbolic connection
Is_readable-to determine whether a given file name is readable
is_uploaded_file-to determine if the file was uploaded via HTTP POST
Is_writable-determines whether a given file name can be written
Aliases for Is_writeable-is_writable
Note: The above functions are used to determine whether a file or directory conforms to the corresponding condition, and returns TRUE or false.

Lchgrp-changes Group Ownership of Symlink
Lchown-changes user ownership of Symlink
link-Establish a hard connection
Linkinfo-get information on a connection
Lstat-gives information about a file or symbolic connection
mkdir-New Directory
Move_uploaded_file-moving uploaded files to a new location
parse_ini_file-parsing a configuration file
pathinfo-return the file path information
pclose-closing Process file pointers
popen-opening a process file pointer
readfile-output a file
readlink-returns the target to which the symbolic connection is pointing
realpath-returns the normalized absolute path name
rename-renaming a file or directory
Rewind-Rewind the position of the file pointer
rmdir-Deleting a directory
Aliases for Set_file_buffer-stream_set_write_buffer
Stat-give the information of the file
symlink-establishing symbolic connections
tempnam-to create a file with a unique file name
tmpfile-Creating a temporary file
touch-setting file access and modification times
umask-Change the current umask
clearstatcache-clearing the file state cache

http://www.bkjia.com/PHPjc/735242.html www.bkjia.com true http://www.bkjia.com/PHPjc/735242.html techarticle basename-Returns the file name part of the path dirname-the directory part of the return path copy the code code as follows: String basename (String $path [, String $suffix]) string dir ...

  • 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.