php中unlink()、mkdir()、rmdir()等方法的使用介绍_php技巧
unlink()函数删除文件 、mkdir()函数创建目录、rmdir()函数删除目录
//使用unlink函数删除文件
$filename="data.txt"; //定义变量
unlink($filename); //用unlink函数删除文件,这里的filename应该是相对的地址,也就是说将当前网页目录下的data.txt删除掉。如果成功则返回 TRUE,失败则返回 FALSE。
//今天刚在服务器上使用unlink函数的时候,用相对地址就报错,找不到文件,于是改为绝对地址,就删除掉了!本机是window,服务器是lunix。暂时就是window下用相对地址,lunix下用绝对地址!大家用了看看,是不是这样,再帮确认下!
//使用mkdir函数创建目录
$dirname="mydir"; //定义变量
mkdir($dirname,0700); //用mkdir来创建目录,这里的目录也是相对的就是在这个网页的目录下再创建一个名为“mydir”的目录!如果成功则返回 TRUE,失败则返回 FALSE。
//今天刚 在服务器上使用unlink函数的时候,用相对地址就报错,找不到文件,于是改为绝对地址,就删除掉了!本机是window,服务器是lunix。暂时就 是window下用相对地址,lunix下用绝对地址!大家用了看看,是不是这样,再帮确认下!
?>
//使用rmdir函数删除目录
$dirname="mydir"; //定义变量
rmdir($dirname); //用rmdir来删除目录,这里的目录也是相对的就是在这个网页的目录下一个名为“mydir”的目录删除!如果成功则返回 TRUE,失败则返回 FALSE。
//今天刚 在服务器上使用unlink函数的时候,用相对地址就报错,找不到文件,于是改为绝对地址,就删除掉了!本机是window,服务器是lunix。暂时就 是window下用相对地址,lunix下用绝对地址!大家用了看看,是不是这样,再帮确认下!
?>
呵呵,简单的应用!系统里总是要上传图片,文档之类的,后台管理里面都是删除记录,而不删除实际已经上传的图档。现在服务器很臃肿了,原来删除指定的文件也不难,就unlink函数就好!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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);".

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(): 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

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

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.

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.

Detailed explanation and examples of Linux command mkdir In Linux systems, the mkdir command is used to create directories and has strong flexibility and practicality. Through the mkdir command, users can quickly create a directory structure to facilitate management of files and data. This article will introduce the use of the mkdir command in detail and give specific code examples to demonstrate its functions. 1. Introduction to the mkdir command mkdir is the abbreviation of "makedirectory" in English and is used to create a new directory. its basic

How to use the Linux command mkdir to create a directory In a Linux system, use the mkdir command to create a directory. mkdir is the abbreviation of makedirectory. This command can easily create a new directory in the file system. The following will introduce in detail how to use the mkdir command to create a directory and provide specific code examples. 1. Basic syntax The basic syntax of the mkdir command is as follows: mkdir[OPTION]DIRECTORY...where,
