Home Backend Development PHP Tutorial php中unlink()、mkdir()、rmdir()等方法的使用介绍_php技巧

php中unlink()、mkdir()、rmdir()等方法的使用介绍_php技巧

May 17, 2016 am 09:07 AM
mkdir rmdir unlink

unlink()函数删除文件 、mkdir()函数创建目录、rmdir()函数删除目录

复制代码 代码如下:



unlink()函数使用实例



//使用unlink函数删除文件
$filename="data.txt"; //定义变量
unlink($filename); //用unlink函数删除文件,这里的filename应该是相对的地址,也就是说将当前网页目录下的data.txt删除掉。如果成功则返回 TRUE,失败则返回 FALSE。
//今天刚在服务器上使用unlink函数的时候,用相对地址就报错,找不到文件,于是改为绝对地址,就删除掉了!本机是window,服务器是lunix。暂时就是window下用相对地址,lunix下用绝对地址!大家用了看看,是不是这样,再帮确认下!




mkdir()函数使用实例



//使用mkdir函数创建目录
$dirname="mydir"; //定义变量
mkdir($dirname,0700); //用mkdir来创建目录,这里的目录也是相对的就是在这个网页的目录下再创建一个名为“mydir”的目录!如果成功则返回 TRUE,失败则返回 FALSE。
//今天刚 在服务器上使用unlink函数的时候,用相对地址就报错,找不到文件,于是改为绝对地址,就删除掉了!本机是window,服务器是lunix。暂时就 是window下用相对地址,lunix下用绝对地址!大家用了看看,是不是这样,再帮确认下!
?>




rmdir()函数使用实例



//使用rmdir函数删除目录
$dirname="mydir"; //定义变量
rmdir($dirname); //用rmdir来删除目录,这里的目录也是相对的就是在这个网页的目录下一个名为“mydir”的目录删除!如果成功则返回 TRUE,失败则返回 FALSE。
//今天刚 在服务器上使用unlink函数的时候,用相对地址就报错,找不到文件,于是改为绝对地址,就删除掉了!本机是window,服务器是lunix。暂时就 是window下用相对地址,lunix下用绝对地址!大家用了看看,是不是这样,再帮确认下!
?>



呵呵,简单的应用!系统里总是要上传图片,文档之类的,后台管理里面都是删除记录,而不删除实际已经上传的图档。现在服务器很臃肿了,原来删除指定的文件也不难,就unlink函数就好!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use unlink to delete a folder in php How to use unlink to delete a folder in php Sep 26, 2021 pm 05:52 PM

How to use unlink to delete a folder in php: 1. Create a php sample file; 2. Pass "if ($handle = opendir( "$dirName" ) ) {while (false !== ($item = readdir( $handle ))){if($item...}" statement can be used to delete the folder.

Introduction to PHP functions—unlink(): delete files Introduction to PHP functions—unlink(): delete files Jul 25, 2023 pm 10:19 PM

Introduction to PHP functions—unlink(): Overview of deleting files: In PHP, unlink() is a function that deletes files. It can help us delete files under the specified path in code. Syntax: unlink(string$filename[,resource$context]):bool Parameters: filename: required, the file path to be deleted, which can be a relative path or an absolute path. context:can

How to solve the problem of php unlink failure How to solve the problem of php unlink failure Mar 08, 2021 am 11:16 AM

Solution to php unlink failure: 1. Open the corresponding PHP sample file; 2. Release the process occupation of the image through "unset($info);"; 3. Re-execute the "@unlink" operation, the syntax is "@unlink( $filePath);".

Quickly master the usage skills of Linux command mkdir Quickly master the usage skills of Linux command mkdir Mar 19, 2024 pm 03:06 PM

Linux system is an operating system widely used in servers and personal computers, with rich command line tools. Among them, the mkdir command is one of the common commands used to create directories. This article will introduce how to quickly master the use of mkdir command, and attach specific code examples. 1. Basic syntax The basic syntax of mkdir is as follows: mkdir [option] directory name where [option] represents optional parameters, and directory name is the name of the directory to be created. The following are some commonly used options: -p: recursively create the directory

The main difference between rmdir and rm commands in Linux! The main difference between rmdir and rm commands in Linux! Feb 20, 2024 am 09:30 AM

In the Linux system, the rmdir and rm commands are both used to delete files and directories. They are also one of the very basic commands. Although they have the same function, they have differences. So what are the rmdir and rm commands in Linux? What are the main differences? Let’s take a look at the specific content. In Linux, rmdir and rm are commands used to delete directories, but they have differences. The rmdir command is used to delete an empty directory. If there are files or subdirectories in the directory, it cannot be deleted and an error message will be displayed. Therefore, rmdir is usually used to empty a directory that contains no content. The rm command is used to delete files and directories. When deleting a directory, you need to add the -r option to delete the directory and its contents.

What does the linux command mkdir execute? What does the linux command mkdir execute? Mar 13, 2023 am 09:29 AM

The linux command mkdir executes to create a directory. This command creates a directory named by dirname. If no path name is added in front of the directory name, the directory specified by dirname is created in the current directory; if an existing path is given , a specified directory will be created under this directory.

How to use the rmdir command under Linux How to use the rmdir command under Linux May 11, 2023 pm 04:52 PM

rmdir is a commonly used command. The function of this command is to delete empty directories. A directory must be empty before it is deleted. (Note that the rm-rdir command can replace rmdir, but it is very dangerous.) When deleting a directory, you must also have write permissions on the parent directory. 1. Command format: rmdir[option]...directory...2. Command function: This command deletes one or more subdirectory items from a directory. When deleting a directory, you must also have write permissions on the parent directory. 3. Command parameters: -p recursively deletes the directory dirname. When the subdirectory is deleted and its parent directory is empty, it will also be deleted. If the entire path is deleted or part of the path is retained for some reason, the system displays the appropriate information on standard output.

How to use the mkdir command under Linux How to use the mkdir command under Linux May 29, 2023 am 11:22 AM

The linuxmkdir command is used to create a directory with a specified name. The user who creates the directory is required to have write permissions in the current directory, and the specified directory name cannot be an existing directory in the current directory. 1. Command format: mkdir [option] directory...2. Command function: The mkdir command can be used to create a folder or directory named by dirname (specified file name) at the specified location. The user who creates a folder or directory must have write permissions on the parent folder of the folder being created. Moreover, the created folder (directory) cannot have the same name as the file name in its parent directory (that is, the parent folder), that is, there cannot be a file with the same name in the same directory (case-sensitive). 3. Command parameters: -m, --mode=mode

See all articles