Last active
March 16, 2019 00:49
-
-
Save pokemaobr/c47f97eed0e383d0eece62c7c605a8a9 to your computer and use it in GitHub Desktop.
Ajuda a pergunta do facebook sobre listagens de pasta e arquivos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = 'Home'; //caminho para sua pasta principal | |
$iterator = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($path), | |
RecursiveIteratorIterator::SELF_FIRST); | |
$content = array(); | |
foreach($iterator as $file) { | |
if($file->isDir()) { | |
if(!in_array(basename($file->getPath()),$content) && basename($file->getPath() != $path)) { | |
$data = DateTime::createFromFormat('d-m-Y', basename($file->getPath())); | |
if (!empty($data)) { | |
$content[] = $data->format('d'); | |
$content[] = strtoupper($data->format('M')); | |
$content[] = $data->format('Y'); | |
} | |
$content[] = basename($file->getPath()); | |
} | |
} | |
else { | |
if(!in_array(basename($file->getFileName()),$content)) | |
$content[] = basename($file->getFileName()); | |
$content[] = $file->getExtension(); | |
} | |
} | |
print_r($content); //todas as variáveis que vc precisa estão na variável content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = 'Home'; //caminho para sua pasta principal | |
$iterator = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($path), | |
RecursiveIteratorIterator::SELF_FIRST); | |
$content = array(); | |
$content[0] = array(); | |
$key=0; | |
foreach($iterator as $file) { | |
if($file->isDir()) { | |
if(!in_array(basename($file->getPath()),$content[$key]) && basename($file->getPath() != $path)) { | |
$data = DateTime::createFromFormat('d-m-Y', basename($file->getPath())); | |
if (!empty($data)) { | |
$key = basename($file->getPath()); | |
$content[$key][] = $data->format('d'); | |
$content[$key][] = strtoupper($data->format('M')); | |
$content[$key][] = $data->format('Y'); | |
} | |
$content[$key][] = basename($file->getPath()); | |
} | |
} | |
else { | |
if(!in_array(basename($file->getFileName()),$content)) | |
$content[$key][] = basename($file->getFileName()); | |
$content[$key][] = $file->getExtension(); | |
} | |
} | |
array_shift($content); | |
print_r($content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment