Ask Your Question
4

Is it possible to use PHP for the removal of all files within a folder?

asked 2022-07-18 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-12-22 23:00:00 +0000

qstack gravatar image

Yes, it is possible to use PHP for the removal of all files within a folder. Here is an example code snippet:

$folder_path = "path/to/folder";

// Get all the files within the folder
$files = glob($folder_path . '/*');

// Loop through each file and remove it
foreach ($files as $file) {
    if (is_file($file)) {
        unlink($file);
    }
}

This code will remove all files within the specified folder by using the glob function to retrieve a list of all files within the folder and then looping through each file and deleting it using the unlink function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-07-18 11:00:00 +0000

Seen: 7 times

Last updated: Dec 22 '22