First, Introduction
In any computer device, files are all necessary objects, and in Web programming, the operation of the file has always been a headache for web programmers, and, the operation of the file in the CMS system is a must, very useful,
Iterator mode
Echo ' program start: '. Time (). '
';
$path = ' d:/www ';
Getrevdir ($path);
Echo ' program end: '. Time (). '
';
Exit
Echo '
';Get all directories and filenames under the current pathThis usage is mainly used in the B/s program to
The opendir () function is used to open the directory handle.If the function runs successfully, a set of directory streams (a set of directory strings) are returned. If the function fails, an error [error] is returned. You can add "@" at the
BaseName ()
Returns the file name portion of the path
$path = "d:/lamp/apache2/htdocs/file.php";
Echo basename ($path). "";
Display filenames with file name extensions
Echo basename ($path, ' php ').";
Show filenames
The following is the program code: The code is as follows:Copy code Function mkdirs ($ dir){If (! Is_dir ($ dir )){If (! Mkdirs (dirname ($ dir ))){Return false;}If (! Mkdir ($ dir, 0777 )){Return false;}}Return true;}Mkdirs ('div/css/layout ');
This code comes from the php Tutorial cms and feels very good, so I will share it with you. If you need it, please refer to it./*** File scanning* @ Param $ filepath Directory* @ Param $ whether to search for sub-directories* @ Param $ ex search
Traverse all files and folders in a folder and copy the matched files to the same directory. In the following example, all the html files in the "/www/pooy/Ke" directory are copied to the "/www/pooy/bk" directory. The code is as follows:Copy code
Rmdir ($ path)The file with the path in $ path will be deleted .(First, we will introduce a function that reads data from a directory, such as opendir (), readdir (), and closedir (). When using this function, we will first open the file handle and
In Windows we habitually use "\" as the file delimiter, but the system does not recognize the logo on Linux, so we will introduce this PHP built-in variables: directory_separator
Path delimiter
Windows
\ or/
In PHP There are many ways to put the directory of all the files listed in the code, with E*/
$list = Scandir (".");$zipname = "";foreach ($list as $file){if ($file = = "." | | $file = = "...") Continue$b =substr ($file,-3);if ($b = = ". Gz" | | $b
Header (' content-type:text/html;charset=utf-8; ');#目录操作函数详解1.GETCWD (OID): Returns False if the current directory is successfully returnedEcho ' 1.GETCWD (): ';Echo GETCWD ();2.chdir (): Function changes the current directory to the specified
directory, file operation details-php
Write a file and read the file in the same way, first see if you can write: $file = ' dirlist.php ';if (is_writable ($file) = = False) {Die ("I am
a file function library
1, the ReadFile () function reads the file and writes it to the cache.
Create a new 01.txt, write something
PHP ReadFile
Create a PHP file
2, fopen open the file
The first parameter of the fopen () function
1. File directory operation
The top stop record is the disk root directory, with '/' or '/'
Current directory./
.. /Represents the Apache directory, the Htdocs directory
1. Create and delete directories mkdir
Copy CodeThe code is as follows:
if
1. Single ChoiceThe folders under the test directory are as follows:Read the following code, and the correct output is () (select an item)AArray([file]=>Array( [0] = test\2.txt) [dir]=>( [0] = =test\c)) BArray([file]=>Array(
It's okay, I wrote a list of functions I want to turn off.
Includes traversing files under this folder, directory subdirectories reading current files under directories and files delete directory subdirectories under current folder and files above
Copy Code code as follows:
$dir = "./";
Open a known directory, and proceed to read its contents
if (Is_dir ($dir))
{
if ($dh = Opendir ($dir)) {
while (($file = Readdir ($DH))!== false) {
echo "FileName: $file: filetype:". FileType
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.