samoht Posted October 30, 2008 Share Posted October 30, 2008 Hello, I am wondering how to look for files in a directory with php? I want to be able to loop through a given directory and return the name of all files of a certain type. I am sure this should be possible - but how?? Thanks Link to comment https://forums.phpfreaks.com/topic/130664-solved-find-files-in-a-directory/ Share on other sites More sharing options...
teng84 Posted October 30, 2008 Share Posted October 30, 2008 http://www.php.net/manual/en/function.glob.php http://www.php.net/manual/en/function.readdir.php Link to comment https://forums.phpfreaks.com/topic/130664-solved-find-files-in-a-directory/#findComment-678031 Share on other sites More sharing options...
samoht Posted October 30, 2008 Author Share Posted October 30, 2008 very cool now how can I push them into and array called $attachments? I have: <? $f=1; $fdate = "invoices/*-invoice_".date('m-d-Y').".doc"; foreach (glob("$fdate") as $filename) { echo '<input type="hidden" id="att'.$f.'" name="att'.$f.'" value="'.$filename.'"> '. "\n"; $f++; } which works fine for putting the files into hidden inputs - but I need to have them in an array ?? Link to comment https://forums.phpfreaks.com/topic/130664-solved-find-files-in-a-directory/#findComment-678776 Share on other sites More sharing options...
kenrbnsn Posted October 30, 2008 Share Posted October 30, 2008 The glob function returns an array. Just do <?php $files = glob($fdate); ?> Ken Link to comment https://forums.phpfreaks.com/topic/130664-solved-find-files-in-a-directory/#findComment-678786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.