简体   繁体   English

单个PHP文件,可以擦除包含子文件夹和文件本身的文件夹中的所有内容

[英]Single PHP file that can erase all the contents inside a folder with sub-folders included and the file itself

I found myself with a huge challenge and I wonder how can I create this, so I've decided to ask for help. 我发现自己面临着巨大的挑战,我想知道如何创建这个挑战,所以我决定寻求帮助。 This is my problem: 这是我的问题:

I need a single PHP file that is capable to delete the entire folder and sub folders inside my domain name, that upon deletion, also the file disappears (gets deleted). 我需要一个PHP文件,该文件能够删除域名中的整个文件夹和子文件夹,删除后该文件也会消失(被删除)。

I am not sure how to do this, I can show the files under a domain name with a single PHP script, however, it requires me to delete the files by selecting them and then press a delete button to complete my action, I am looking for a PHP script that not also deletes all the files and folders, but can delete itself after completing the task. 我不确定如何执行此操作,我可以使用单个PHP脚本显示域名下的文件,但是,它要求我通过选择文件来删除文件,然后按删除按钮以完成操作,我正在寻找适用于一个PHP脚本,该脚本也不会删除所有文件和文件夹,但是可以在完成任务后自行删除。

Any help is much appreciated, thanks in advance! 非常感谢您的帮助,在此先感谢您!

This question was being asked before the solution is simple. 在解决方案很简单之前就曾问过这个问题。 First, you need to delete all the files with the script and then the folder. 首先,您需要使用脚本删除所有文件,然后删除文件夹。 Here is the Script that you needed ' 这是您需要的脚本'

https://stackoverflow.com/a/3349792/9638167 https://stackoverflow.com/a/3349792/9638167

This will surely help. 这肯定会有所帮助。

  1. Put script to any folder 将脚本放入任何文件夹
  2. Exec 执行力
  3. Folder is delete 文件夹已删除

rrmdir(__DIR__);

Function implementation in How do I recursively delete a directory and its entire contents (files + sub dirs) in PHP? 如何在PHP中递归删除目录及其全部内容(文件+子目录)中的函数实现

There are several ways to do that. 有几种方法可以做到这一点。 One of them is using exec. 其中之一是使用exec。

For linux you can use 对于Linux,您可以使用

exec ('rm -rf /path/to/folder');

and for windows you have 对于Windows

exec ('rmdir path/to/folder /S /Q');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM