On 6/21/07, Edward Kay <edward@xxxxxxxxxx> wrote:
> -----Original Message----- > From: Graham Shaw [mailto:zaknafien@xxxxxxxxxxxxxxxx] > > I'm probably missing something really obvious here but how would > I go about > opening a file or multiple files in a folder without knowing the filename > ahead of time? Read the files in the directory and place the names of the ones you want into an array using the directory functions: http://uk.php.net/manual/en/ref.dir.php Edward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
DISCLAIMER: Once again, I'm programming in the email window without testing the code at all. In theory, it should work, but there's probably a bug somewhere. <? function ls($d='',$f='') { // Lists files in a directory. /* Default directory is the PWD. Default files are all (non-hidden) files. Usage examples: ls(); // List all non-hidden files in the current directory. ls('/share/files'); // All non-hidden files in /share/files. ls('/home/me/www/','*.php'); // All .php files in /home/me/www/. */ $d && (substr($d,-1,1) != "/") ? $d .= "/" : ''; // Adds trailing slash if needed. $d && !is_dir($d) ? $err = "Not a directory!" : ''; // Checks for existence. !$err ? exec('ls '.$d.$f.' 2>&1',$ret) : $ret = $err; // Redirects error output. // If you want to list files AND directories, comment this section out // and change return $files; below to return $ret; for($i=0;$i<count($ret);$i++) { is_file($ret[$i]) ? $files[] = $ret[$i] : ''; } return $files; // Returns an array of files. } print_r(ls()); ?> -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php