PHP ninth week function learning record

Time:2020-9-17

mkdir()

effect

mkdir()Function to create a directory.TRUE, if failedFALSE

usage

mkdir(path,mode,recursive,context)Path is required. Specifies the name of the directory to create.0777Global access is allowed.0The second number specifies the authority of the owner1 =Executive authority2 =Write permission4 =Read permissionPHP 5New in)PHP 5New in)

move_uploaded_file()

effect

move_uploaded_file()Function to move the uploaded file to a new location.TRUE, if failedFALSE

usage

move_uploaded_file(file,newloc)File is required. Specify the files to be moved.

Tips and notes

Note: this function is only used through theHTTP POSTUploaded files.

parse_ini_file()

effect

parse_ini_file()Function parses a configuration file (INI file) and returns its settings in the form of an array.

usage

parse_ini_file(file,process_sections)File is required. Specify the INI file to be checked.TRUE, a multidimensional array containing the name and settings of each section in the configuration file is returned. The default isFALSE

Tips and notes

Tip: this function can be used to read your own application configuration file with PHP.The INI file does not matter.null、yes、no、trueandfalse。 character{}|&~![()"It can't be used anywhere in the key name

case

// " test.ini "Content:
[names]
me = Robert
you = Peter

[urls]
first = "http://www.example.com"
second = "https://www.runoob.com"

//PHP code
<?php
print_r(parse_ini_file("test.ini"));
?>

result

Array
(
    [me] => Robert
    [you] => Peter
    [first] => http://www.example.com
    [second] => https://www.runoob.com
)

pathinfo()

effect

pathinfo()Function returns information about the file path as an array.[dirname]:Directory path[basename]:file name[extension]:File suffix[filename]:File name without suffix

usage

pathinfo(path,options)Path is required. Specify the path to be checked.PATHINFO_DIRNAME -Only dirname is returnedPATHINFO_BASENAME -Only basename is returnedPATHINFO_EXTENSION -Only extension is returnedPATHINFO_FILENAME -Return only filename

Tips and notes

Note: if not all elements are requested, thepathinfo()Function returns a string.

case

<?php
print_r(pathinfo("/testweb/test.txt"));
?>

result

Array
(
    [dirname] => /testweb
    [basename] => test.txt
    [extension] => txt
    [filename] => test
)

pclose()

effect

pclose()Function closed bypopen()Open process.FALSE

usage

pclose(pipe)Pipe required. Provided bypopen()Open process.

case

<?php
$file = popen("/bin/ls","r");
//some code to be executed
pclose($file);
?>

popen()

effect

popen()The function uses the command parameter to open the process file pointer.FALSE

usage

popen(command,mode)Command is required. Specifies the order to be executed.:Read only.:Write only (open and empty an existing file or create a new file)

case

<?php
$file = popen("/bin/ls","r");
//some code to be executed
pclose($file);
?>

readfile()

effect

readfile()Function reads a file and writes to the output buffer.FALSEError messages are attached. You can do this by adding a'@'To hide the error output.

usage

readfile(filename,include_path,context)Filename is required. Specifies the file to be read..Please set this parameter to'1'

case

<?php
echo readfile("test.txt");
?>

result

There are two lines in this file.
This is the last line.
57

readlink()

effect

readlink()Function returns the destination of the symbolic connection.FALSE

usage

readlink(linkpath)

case

<?php
echo readlink("/user/testlink");
?>

realpath()

effect

realpath()Function returns an absolute path.'/./', '/../'And the superfluous'/')And return the absolute pathname.FALSE

usage

realpath(path)

case

<?php
echo realpath("test.txt");
?>

result

C:Inetpubtestwebtest.txt

rename()

effect

rename()Function to rename a file or directory.TRUE。 If failed, returnFALSE

usage

rename(oldname,newname,context)

case

<?php
rename("images","pictures");
?>

rewind()

effect

rewind()Function to rewind the position of the file pointer back to the beginning of the file.TRUE。 If failed, returnFALSE

usage

rewind(file)

case

<?php
$file = fopen("test.txt","r");

//Change position of file pointer
fseek($file,"15");

//Set file pointer to 0
rewind($file);

fclose($file);
?>

rmdir()

effect

rmdir()Function to delete an empty directory.TRUE。 If failed, returnFALSE

usage

rmdir(dir,context)

case

<?php
$path = "images";
if(!rmdir($path))
{
    echo ("Could not remove $path");
}
?>

set_file_buffer()

effect

set_file_buffer()Function to set the buffer size of the open file.fwrite()Function output. The size of the buffer is usually8K。 Therefore, if two processes are to be written to the same file, each file can only be written into at most once8K and allows other processes to write. If buffer is0The write operation is not buffered (which means that other processes can only be allowed to write after the first write process has completed).0, otherwise returnEOF

usage

set_file_buffer(file,buffer)

case

//Create unbuffered stream
<?php
$file = fopen("test.txt","w");
if ($file)
{
set_file_buffer($file,0);
fwrite($file,"Hello World. Testing!");
fclose($file);
}
?>

stat()

effect

stat()Function returns information about the file.[0]or[dev] -Equipment number[1]or[ino] -Inode number[2]or[mode] -Inode protection mode[3]or[nlink] -Number of connections[4]or[uid] -Owner's userID
    [5]or[gid] -Owner's groupID
    [6]or[rdev] -Inode device type[7]or[size] -The number of bytes of the file size[8]or[atime] -Last access time (UNIX timestamp)[9]or[mtime] -Last modified time (UNIX timestamp)[10]or[ctime] -Last inode change time (UNIX timestamp)[11]or[blksize] -file systemIOBlock size of (if supported)[12]or[blocks] -Number of blocks occupied

usage

stat(filename)

case

<?php
$stat = stat('test.txt');
echo 'Acces time: ' .$stat['atime'];
echo '<br />Modification time: ' .$stat['mtime'];
echo '<br />Device number: ' .$stat['dev'];
?>

result

Access time: 1141633430
Modification time: 1141298003
Device number: 0

symlink()

effect

symlink()Function creates a symbolic connection starting from an existing target file connected by the specified name.TRUE。 If failed, returnFALSE

usage

symlink(target,link)

Tips and notes

Note: This is not aHTMLA connection is a connection in a file system.

tempnam()

effect

tempnam()Function creates a temporary file with a unique file name in the specified directory.FALSE

usage

tempnam(dir,prefix)Dir required. Specifies the directory where temporary files are created.

Tips and notes

Note: if the specified directory does not exist, thentempnam()A file is generated in the system's temporary directory.tmpfile()

case

<?php
echo tempnam("C:inetpubtestweb","TMP0");
?>

result

C:inetpubtestwebTMP1.tmp

tmpfile()

effect

tmpfile()Function to read and write (W+)Pattern creates a temporary file with a unique file name.

usage

tmpfile()

Tips and notes

Note: the temporary file will be closed after the file is closed (with thefclose())Or automatically deleted when the script ends.

case

<?php
$temp = tmpfile();

fwrite($temp, "Testing, testing.");
//Rewind to the start of file
rewind($temp);
//Read 1k from file
echo fread($temp,1024);

//This removes the file
fclose($temp);
?>

result

Testing, testing.

touch()

effect

touch()Function to set the access and modification time of the specified file.TRUE。 If failed, returnFALSE

usage

touch(filename,time,atime)Filename is required. Specify the documents to be contacted.

Tips and notes

Note: if the specified file does not exist, it will be created.

case

<?php
touch("test.txt");
?>

umask()

effect

umask()Function to change the file permissions of a file.PHPThe umask of is set to mask& 0777And return the original umask. However, if you callumask()The current umask will be returned if there is no parameter.

usage

umask(mask)Mask is optional. Define new authority. The default is07770The second number specifies the authority of the owner1 =Executive authority2 =Write permission4 =Read permission

unlink()

effect

unlink()Function to delete a file.TRUE。 If failed, returnFALSE

usage

unlink(filename,context)Filename is required. Specify the files to be deleted.

example

<?php
$file = "test.txt";
if (!unlink($file)) {
    echo ("Error deleting $file");
} else {
    echo ("Deleted $file");
}
?>

source

PHP 5 filesystem function | rookie tutorial