Home
Credits
Affliates
Link Exchange

HTMLshaman
PHPshaman
LINUXshaman

Helpful Links
Web Design Images
Backgrounds
Icon Sets
GIF Images


Simple Scripts : List Contents

Sometimes there will be a need for us to list a number of files or directories inside the directory and this can be used with a combination of SHELL and also PHP array commands.

The basic idea is getting SHELL to execute a show command for the specific file type that we want and then store it in an array before printing it one by one.

The below example wants to show all ZIP files on the directory and allow the user to download them without showing them the otehr files that are inside it. However there is one file that we cannot let them see and download and need to mask it before it prints.

Example :
<?php
// List and store ZIP files names
exec ("ls -d *.zip", $output, $return);

// Find the specific ZIP file and remove from array
$secret_file = array_search('secret.zip', $output);
unset ($output["$secret_file"]);

// Count the number of Files that we have
$totaldir = count($output);
print "We have $totaldir Files for download<br>";
print "Click on the Foile name below to Vstart your downlaod<br><br>";

// List Forums if directory can be opened
if ($return == "0")
{
foreach ( $output as $file )
{
print ("<a href='http://domain.com/$file'>$file</a><br>");
}
}

// If the directory can't be opened print the error message
else
{
print "There is an error in the loading of the directory contents<br>";
}
?>

Where from the code you will see that we can even tell the suer how many files are listed and also mask the existence of the file called "secret.zip" from appearing.

Notes :
The masking happens when we tell the script to search for a file called "secret.zip" using the array_search command and $output is the array holder which will be looked into.
After that is done, $secret_file is merely a number that tells the script which array number this file is located at.
Then lastly on the $output array, we look for the $secret_file which is the array number and the unset it from the array making it non-existent. then print the whole content.






Basics
Introduction
Compilation for Apache

Language Intro
The Basics
Structuring
Script Flow
Functions
Arrays
Objects

Extras
Global values

Simple Scripts
MySQL Query
File Upload
List Contents






Disclaimer:
Contents on this site is provided for educational purposes and will not be distributing source codes from any major commercial reference.
Partial code may be used to provide better understanding of how the program works or functions to illustrate to the reader more clearly.
Other programs that are provided freely on the internet may be placed as a quick solution to the user's needs taking in consideration that it is not altered in any way.

Our Recommended Links
prepaid phone card
Online Casino
Smiley Central
Ventrilo Servers
Counter-Strike Servers
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
phone card

Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Advertise Here
Hollywood Lyrics
Resident Evil
Contact us at webmaster@galacnet.com for advertising opportunities on GalacNet.