php interview topics --- 7 file and directory handling test sites

php interview topics --- 7 file and directory handling test sites

A summary

Sentence summary:

With the mind: the basic file operations and directory operations to understand a wave, do not insist

 

1, constantly writes a line "Hello World" string in the file header hello.txt requiring code integrity?

|||-begin

<? PHP
 // open file
//
// The contents of the file read out at the beginning join Hello World
//
// write the string spliced ​​them back to the file
//
// Hello 7891234567890
//
$file = './hello.txt';
$handle = fopen($file, 'r');
$content = fread($handle, filesize($file));
$content = 'Hello World'. $content;
fclose($handle);
$handle = fopen($file, 'w');
fwrite($handle, $content);
fclose($handle);

|||-end

Can not use the file pointer to the beginning, as it will cover

 

 

2, php access to remote file?

Open allow_url_fopen, HTTP protocol connection can only be read-only, FTP protocol can use read-only or write-only

 

3, php directory manipulation functions?

Name-related: basename (), dirname (), pathinfo ()
Directory read: opendir (), readdir (), closedir (), rewinddir ()
To delete a directory: rmdir (); Create a directory: mkdir ()

 

4, php file operations other functions?

File size: filesize ()
File copy: copy ()
Delete File: unlink ()
File Type: filetype ()
File size: filesize ()
Directory Size: Disk (), free_space (), disk_total_space ()
File copy: Copy ()
Delete File: unlink ()


File Type: filetype ()
Rename the file or directory: the rename ()
Interception file: ftruncate ()
文件属性:file_exists()、is_readable()、is_writable()、is_executable()、filectime()、fileatime()、filemtime()

File locking: Flock ()
File pointer: ftell (), fseek (), rewind ()

 

 

5, by way of traversing the directory PHP function, write a program?

|||-begin

? < PHP
 $ dir = './test' ;
 // Open Directory
// read files among directories
// If the file type is a directory, continue to open directory
// read subdirectories
// If the file type is a file, the output file name
// close the directory 
function loopDir ( $ dir )
{
    $handle = opendir($dir);

    while(false!==($file = readdir($handle)))
    {
        if ($file != '.' && $file != '..')
        {
            echo $file. "\n";
            if (filetype($dir. '/'. $file) == 'dir')
            {
                loopDir ( $ dir . '/'. $ file );
            }
        }
    }
}
loopDir ( $ dir );

|||-end

1、while(false!==($file = readdir($handle)))
2、if ($file != '.' && $file != '..')
3、if (filetype($dir. '/'. $file) == 'dir')

 

 

 

 

 

 

Second, content in summary

 

 

 

 

Reproduced in: https: //www.cnblogs.com/Renyi-Fan/p/11061243.html

Guess you like

Origin blog.csdn.net/weixin_33894992/article/details/93572347