Home> php教程> php手册> body text

Detailed explanation of deleting unlink() in php files

WBOY
Release: 2016-10-28 15:03:27
Original
1549 people have browsed it

Remember the lesson from PHP file creation, we created a file called testFile.txt.

$myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fclose($fh); 判断是否删除了. http://www.manongjc.com/article/1351.html $myFile = "testFile.txt"; unlink($myFile);
Copy after login

Example

$filename = 'file.txt'; fopen($filename,'a+'); if(!unlink($filename)) { echo "文件{$filename}删除失败"; // http://www.manongjc.com/article/1351.html } else { echo "文件{$filename}删除成功"; } ?>
Copy after login

Delete all files in the directory

function delFileUnderDir( $dirName="../Smarty/templates/templates_c" ) { // http://www.manongjc.com/article/1351.html if ( $handle = opendir( "$dirName" ) ) { while ( false !== ( $item = readdir( $handle ) ) ) { if ( $item != "." && $item != ".." ) { if ( is_dir( "$dirName/$item" ) ) { delFileUnderDir( "$dirName/$item" ); } else { if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item
n"; } } } closedir( $handle ); } }
Copy after login

Related labels:
source:php.cn
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!