List all the files and folders in a Directory csv(file) read with PHP recursive function
<?php/** List all the files and folders in a Directory csv(file) read with PHP recursive function */
function getDirContents($dir, &$results = array()){
$files = scandir($dir);
foreach($files as $key => $value){
$path = realpath($dir.DIRECTORY_SEPARATOR.$value);
if(!is_dir($path)) {
$results[] = $path;
} else if($value != "." && $value != "..") {
getDirContents($path, $results);
//$results[] = $path;
}
}
return $results;
}
$files = getDirContents('/xampp/htdocs/medifree/lab');//here folder name where your folders and it's csvfile;
foreach($files as $file){
$csv_file =$file;
$foldername = explode(DIRECTORY_SEPARATOR,$file);
//using this get your folder name (explode your path);
print_r($foldername);
if (($handle = fopen($csv_file, "r")) !== FALSE) {
fgetcsv($handle);
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$col[$c] = $data[$c];
}
}
fclose($handle);
}
}
?>
No comments:
Post a Comment
Thank You For Comment