php 删除一组文件的简单示例

前端之家收集整理的这篇文章主要介绍了php 删除一组文件的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
PHP删除一组文件感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
在web开发中经常会有选择多个内容进行操作的情况,我们看下PHP如何删除一组文件的。
form.html

<!-- These files must exist to work (This is only an example) -->
<form action="process.PHP" method="post">
<input type="checkBox" value="file1.html" name="delete[]"> file1.html<br>
<input type="checkBox" value="file2.html" name="delete[]"> file2.html<br>
<input type="checkBox" value="file3.html" name="delete[]"> file3.html<br>
<input type="submit" value="Delete Selected" name="submit">
</form>

process.PHP

/**
 * PHP删除一组文件
 *
 * @param 
 * @arrange 512-笔记网: www.512Pic.com
 **/
<?PHP
# Take each checked value,and give it a name of $delete
foreach($_POST['delete'] as $delete){
# Make sure the file actually exists
if(file_exists("/location/of/directory/".$delete)){
# Delete each file
unlink("/location/of/directory/",$delete);
}else{
continue;
}
}
# Return to form.html
header("Location: form.html");

/***   来自编程之家 jb51.cc(jb51.cc)   ***/
原文链接:https://www.f2er.com/php/528254.html

猜你在找的PHP相关文章