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 Quote 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 Quote 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 ?? Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.