Scanning All Files and Directories

Scanning All Files and Directories


Anda dapat membuat Fungsi scanning dalam PHP.

Scanning berikut menghasilkan query dalam bentuk array, dan bersifat continue sampe file terakhir pada folder terakhir, jadi smua bakalan discan, kecuali untuk nilai pada variable $invisibleFileNames yang ditampung juga dalam array

Pengen Belajar Web Development HTML CSS JQuery Javascript Codeigniter Lebih Lengkap, Mudah, dan Lebih Terstruktur?

Pake Modul Video Tutorial Interaktif Mudah Jelas Gamblang, Nggak Pakai Ribet, Kenapa Video? Kalo Ebook Atau Buku Tebelnya minta ampun Gan. Mumpung Ada Promo, Beli Sekarang Dah Gan!! Promo Tutorial Premium Mahir Web Development Bangun 5 Project Website + Mahir Membuat 4 Aplikasi Android + Bonus Tutorial Membuat Themes Wordpress Premium, 3 Tutorial Isi 5 Dvd Cuma Rp 150rb Aja Gan (harga normal Rp 296rb) !!! Terbatas Sampe 12 Februari 2020 (Yang Bikin Videonya Udah Pengalaman Di Web Development Lebih Dari 15 Tahun Gan!!) (Pemesanan bisa SMS/WA ke 0838 1157 5876, atau bisa pesan secara online di sini)


<?php
function scanDirectories($rootDir) {
??? // set filenames invisible if you want
??? $invisibleFileNames = array(".", "..", ".htaccess", ".htpasswd", "Thumbs.db");
??? // run through content of root directory
??? $dirContent = scandir($rootDir);
??? $allData = array();
??? // file counter gets incremented for a better
??? $fileCounter = 0;
???
??? foreach($dirContent as $key => $content) {
??????? // filter all files not accessible
??????? $path = $rootDir.'/'.$content;
??????? if(!in_array($content, $invisibleFileNames)) {
??????????? // if content is file & readable, add to array
??????????? if(is_file($path) && is_readable($path)) {
??????????????? $tmpPathArray = explode("/",$path);
??????????????? // saving filename
??????????????? $allData[$fileCounter]['fileName'] = end($tmpPathArray);
??????????????? // saving while path (for better access)
??????????????? $allData[$fileCounter]['filePath'] = $path;
??????????????? // get file extension
??????????????? $filePartsTmp = explode(".", end($tmpPathArray));
??????????????? $allData[$fileCounter]['fileExt'] = end($filePartsTmp);
??????????????? // get file date
??????????????? $allData[$fileCounter]['fileDate'] = date('Y-m-d H:i:s', filectime($path));
??????????????? // get filesize in byte
??????????????? $allData[$fileCounter]['fileSize'] = filesize($path);
??? ??? ??? ???
??? ??? ??? ??? //query SQL dapat diletakkan disini:
??? ??? ??? ??? //mysql_query("INSERT INTO dirGue(path, filename) VALUES('".$allData[$fileCounter]['filePath']."', '".$allData[$fileCounter]['fileName']."')")
??? ??? ??? ???
??????????????? $fileCounter++;
??????????? // if content is a directory and readable, add path and name
??????????? }elseif(is_dir($path) && is_readable($path)) {
??????????????? $dirNameArray = explode('/',$path);
??????????????? $allData[$path]['dirPath'] = $path;
??????????????? $allData[$path]['dirName'] = end($dirNameArray);
??????????????? // recursive callback to open new directory
??????????????? $allData[$path]['content'] = scanDirectories($path);
??????????? }
??????? }
??? }
???
??? return $allData;
}

if(isset($_POST['submit']) && !empty($_POST['rootDir']))
{
??? print_r(scanDirectories($_POST['rootDir']));
}
?>

<h2>Scanning All Files and Directories
</h2>
<form action="" method="post">
<input name="rootDir" type="text" size="20" />
<input name="submit" type="submit" value="scan directories" />
</form>

Selamat mencoba :D~~

Artikel Terkait :