Menu
Free Stuff:
Sponsors & Spotlight
Free Web Studio!
   The Insomnia Web Studio by Tech 3 Software is availible now for download. It features TTW which makes all the difference and is software that we use ourselves.
Read More...
 iCoder (The Web Site for Web Developers)
 PHP Descriptive File Archiver:
   This isn't too big of a script, but we'll say it so you can understand it. This tutorial will go through how to list files in a directory, then filter the types of files by extension. Then determining the size of the files in (B,KB,MB). And finally, opening and displaying a file which contains the description of the file which name is the files name but with a ".DSC" extension.

 Listing The Files & Sizes:
   This is the piece of the script where we get the names of the files from a determined directory and then determine the sizes of the files and create an output variable.

$seldir = getcwd();
$filesat = "qbg"; //qbg is the determined directory
$filels=opendir($filesat);
$r=0;
while (false !== ($file = readdir($filels))) { //repeat until there are no more files in the directory
$r = $r + 1; //Determining the files size in (B,KB,MB) and so on.
if ($r > 2){
$kb = 1024;
$mb = 1024 * $kb;
$gb = 1024 * $mb;
$tb = 1024 * $gb;
$xfile = "qbg/". $file;
$size = filesize($xfile);

if($size < $kb) { //Creating the output variable of the file & it's size
$esta = $size." B";
}
else if($size < $mb) {
$esta = round($size/$kb,2)." KB";
}
else if($size < $gb) {
$esta = round($size/$mb,2)." MB";
}
else if($size < $tb) {
$esta = round($size/$gb,2)." GB";
}
else {
$esta = round($size/$tb,2)." TB";
}


 Filtering The Files and determining the description files:
list ($File_name, $Exten) = split('\.', $file);
if ($Exten == "bas"){
$Desc = "qbg/".$File_name.".dsc";
if (file_exists($Desc)) {
$uno = "x";
$rol = $rol +1;
} else {
$Desco = "No Description"; //If Description File Doesn't Exist
$uno="y";
$rol = $rol +1;
}