Tom Chubb wrote: > Got it working fine. Thanks Vincent and Jochem for pointing me in the > right direction. Here is the code I used in case anyone's > interested... > > <?php > foreach(glob($path.$id."{*.doc,*.pdf,*.txt,*.rtf}", > GLOB_BRACE) as $filename) { $cvs[]=$filename; } > > //Loop through the four possible extensions > $i = 0; > while ($i <= 3) { > //Check there is a value before displaying why? glob only finds things if they exist. *looks* like a misunderstanding of GLOB_BRACE. why 2 loops? > if(!empty($cvs[$i])) { > $cv = str_replace($path, "", $cvs[$i]) ; > echo "<a href=\"$cvs[$i]\">$cv</a>"; > echo "<br>"; > } > echo "\n"; > $i++; this shouldn't work. at least the links shouldn't work unless the files are on a local disk (which is a web scenario is unlikely). foreach(glob($path.$id."{*.doc,*.pdf,*.txt,*.rtf}",GLOB_BRACE) as $f) { echo '<a href="',makeFilePathIntoValidURL($f),'">',basename($f),'</a><br />'; } // just a example/idea - I assume the 'id' files are accessible via the web function makeFilePathIntoValidURL($f) { if (!strpos($f, $_SERVER['DOCUMENT_ROOT']) === 0) return '#nolink'; return str_replace($_SERVER['DOCUMENT_ROOT'], $f); } > > } > ?> > > On 28/11/06, Tom Chubb <tomchubb@xxxxxxxxx> wrote: >> Thanks guys, >> Looks like just what I need. Will test it out later. >> >> Tom >> >> On 28/11/06, Vincent DUPONT <Vincent.dupont@xxxxxxx> wrote: >> > >> > yes, glob works well. >> > here is an example to get pictures inside a folder ($path) >> > >> > foreach(glob($path."/*/{*.gif,*.jpg,*.JPG,*.jpeg,*.JPEG,*.png}", >> GLOB_BRACE) as $filename){ >> > $pics[]=$filename; >> > } >> > >> > vincent >> > -----Original Message----- >> > From: Jochem Maas [mailto:jochem@xxxxxxxxxxxxx] >> > Sent: Tue 28/11/2006 10:59 >> > To: Tom Chubb >> > Cc: [php] PHP General List >> > Subject: Re: Readdir >> > >> > Tom Chubb wrote: >> > > What would be the best way to retrieve a list of files from an upload >> > > folder that are called "id" where the extension could be .doc .txt or >> > > .pdf >> > > For example, I have a folder where people can upload a document and >> > > the document is renamed as their user id. They can upload a PDF, DOC >> > > or TXT file. They may wish to upload one of each. I am using >> > > file_exists for each case, but is there an easier/tidier way of doing >> > > it? >> > > Thanks in advance, >> > > >> > > Tom >> > > >> > >> > try the glob() function, something like: >> > >> > $id = getUserId(); >> > foreach (glob("/path/to/user/files/$id.*") as $file) { >> > echo $file,"<br />"; >> > } >> > >> > -- >> > PHP General Mailing List (http://www.php.net/) >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > -- >> > PHP General Mailing List (http://www.php.net/) >> > To unsubscribe, visit: http://www.php.net/unsub.php >> > >> > >> > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php