|
|
|
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.
|
| Our Recommended Links |
|
|
Contact us at webmaster@galacnet.com for advertising opportunities on GalacNet. |