I am using this peice of code:
$target = \'extracted/\' . $name[0];
$scan = scandir($target);
To scan the directory of a folder which is
The quick and dirty way:
$folders = glob("<path>/*", GLOB_ONLYDIR);
A more versatile and object-oriented solution, inspired by earlier answers using DirectoryIterator but slightly more concise and general purpose:
$path = '<path>';
$folders = [];
foreach (new \DirectoryIterator($path) as $file)
{
if (!$file->isDot() && $file->isDir())
{
$folders[] = $file;
}
}
To determine whether or not you have a folder or file use the functions is_dir()
and is_file()
For example:
$path = 'extracted/' . $name[0]; $results = scandir($path); foreach ($results as $result) { if ($result === '.' or $result === '..') continue; if (is_dir($path . '/' . $result)) { //code to use if directory } }
First off, rmdir() cannot delete a folder with contents. If safe mode is disabled you can use the following.
exec("rm -rf folder/");
Also look at is_dir()/is_file() or even better the PHP SPL.