alanl1 Posted May 17, 2013 Share Posted May 17, 2013 Hi Professionals I have the following piece of code that shows the files in a directory. What I want to to ias only show files of type .xls and xlsx can this be done? here is my code <?php include("header.php"); ?> <table width="100%" border="0"> <tr> <td width="34%"> </td> <td width="20%"> </td> <td width="46%"> </td> </tr> <tr> <td width="34%"> </td> <td width="20%"> <?phpecho "<form name=\"pickfile\" action=\"uploadedfile.php\">"; echo "<select name='yourfiles'>"; $dirpath = "C:/inetpub/wwwroot/tocleanse/";$dh = opendir($dirpath); while (false !== ($file = readdir($dh))) { if (!is_dir("$dirpath/$file")) {echo "<option value='$file'>" . $file . '</option>';}}closedir($dh); echo "</select>"; ?></td> <td width="46%"><?php echo "<button type=\"submit\" name=\"pickfile\">Upload File</button>\n";echo "</form>"; ?></td> </tr></table> Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/278086-drop-down-box-directory-values/ Share on other sites More sharing options...
requinix Posted May 17, 2013 Share Posted May 17, 2013 Seeing as how your question is can this be done?Yes. As for the question you implied, try either glob with new code to use it, or keeping your current code and making it check the extension of $file. Quote Link to comment https://forums.phpfreaks.com/topic/278086-drop-down-box-directory-values/#findComment-1430587 Share on other sites More sharing options...
alanl1 Posted May 17, 2013 Author Share Posted May 17, 2013 i am pretty new to php what do you mean by checking the extensions of $file thanks alan Quote Link to comment https://forums.phpfreaks.com/topic/278086-drop-down-box-directory-values/#findComment-1430589 Share on other sites More sharing options...
requinix Posted May 17, 2013 Share Posted May 17, 2013 Well, I think a good first question would be "How much PHP do you know?" Because you'll have to write some code. Quote Link to comment https://forums.phpfreaks.com/topic/278086-drop-down-box-directory-values/#findComment-1430594 Share on other sites More sharing options...
alanl1 Posted May 23, 2013 Author Share Posted May 23, 2013 not much at all Quote Link to comment https://forums.phpfreaks.com/topic/278086-drop-down-box-directory-values/#findComment-1431955 Share on other sites More sharing options...
Solution requinix Posted May 23, 2013 Solution Share Posted May 23, 2013 (edited) Then now's the time to start on it. To get the file extension, pathinfo is one method you can use. substr is another (pay close attention to the explanation of the $start parameter). Try some examples to see how they work. Edited May 23, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/278086-drop-down-box-directory-values/#findComment-1431961 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.