龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php删除一组文件

时间:2014-06-20 03:16来源:网络整理 作者:网络 点击:
分享到:
php删除一组文件 在web开发中经常会有选择多个内容进行操作的情况,我们看下php如何删除一组文件的。** form.html**```{.php}lt;!-- These files must exist to work (This is only an example) --gt;lt;form actio

在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
# 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");
?>
精彩图集

赞助商链接