SQL PHP HTML ASP JavaScript articles and free scripts to download

scandir()

We can display all directory and files present inside a given directory by using scandir php function. This function returns an array. Here is the syntax.
Scandir('directory_sting',sort_order,'context');
Directy_sting: directory name as string
Sort_order: (Optional)The listing order is ascending by default ( alphabetical ). Can by changed by SCANDIR_SORT_DESCENDING and Random by SCANDIR_SORT_NONE
Context: ( Optional )

Here is the simple code to list all files and directory present in a directory.
$ar=scandir('test_dir'); // Change this input 
print_r($ar);
Listing all files and directory of current folder
$ar=scandir('.');  
print_r($ar);
Listing all files and directory of up folder
$ar=scandir('..'); 
print_r($ar);
We can develop a small script which will first list file and directory of current directory. All listed directory will have hyperlink to list files and directory present inside that on click. We have used is_dir function to check if the output string is a directory or not.
$var=$_GET['var'];
if(strlen($var)==0){
$var='.';
}
$ar=scandir($var);
while (list ($key, $val) = each ($ar)) {
if(is_dir($val)){
echo "<a href=scandir.php?var=$val>$val</a><br>";
}else {
echo "$val<br>";
}
}

Google+
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer