/ Published in: PHP
This script reads a directory of files. After reading the directory specified it outputs the directory files. Upon output, supplied functions manipulate each filename and format it to make the output filename look better. e.g.: instead of output being 'my-good-looking-file.txt' it would look like 'My Good Looking File'.
Expand |
Embed | Plain Text
// This script reads a directory of files. After reading the directory specified it outputs the directory files. // Upon output, supplied functions manipulate each filename and format it to make the output filename look better. // e.g.: instead of output being 'my-good-looking-file.txt' it would look like 'My Good Looking File'. // In order for the output to look better, you must put a hyphen (-) or an underscore (_) between each // word that you want to be separated. // function to strip off the file extension function strip_ext($name) { if($ext !== false) { } return $name; } // function to remove the hyphen or underscore from filename. function removeHyphen($filename) { $target = $filename; $patterns[0] = '/-/'; $patterns[1] = '/_/'; $replacements[0] = ' '; $replacements[1] = ' '; return $filename; } // function to capatalize the first character of each word. Must be called after // the removal of the hyphen or underscore function capFirstWord($word) { $cap = $word; foreach($cap as $key => $value) { } return $word; } // Formats the file. This is the main function that calls all functions explained above. function formatFile($name) { $name = strip_ext($name); $name = removeHyphen($name); $name = capFirstWord($name); return $name; } // Sets up the directory you would like to use as the "reading" directory. while(($file = $mydir->read()) !== false) { // Security - remove "." and ".." files (directories) if ($file != "." && $file != "..") { // Output. This is what is actually outputed by the script and that shows // up on the screen (browser). } } $mydir->close();
Comments
Subscribe to comments
You need to login to post a comment.

this is a very nice script... but if you first save in a database the name of the file what you are uploading in a directory...and then you view the list in a table with all the file you uploaded from the database ...it`s posible to make an link on the database showed filename to the file saved in one directory on the disk?