koo_04 Posted February 7, 2011 Share Posted February 7, 2011 I am using glob() to see a list of .zip files on my website. I wanted to display them on a drop down list. I got that working fine, but the file path shows up with it. Any idea how to remove it? Here is the code I am using. <?php $dir = "/downloads/"; $files = glob($dir."*.zip", GLOB_NOSORT); echo'<select name="Files">'; foreach($files as $file){ echo'<option value="'.$file.'">'.$file.'</option>'; } echo'</select>'; ?> Link to comment https://forums.phpfreaks.com/topic/226933-removing-the-file-path-when-using-glob/ Share on other sites More sharing options...
kenrbnsn Posted February 7, 2011 Share Posted February 7, 2011 Look at basename Ken Link to comment https://forums.phpfreaks.com/topic/226933-removing-the-file-path-when-using-glob/#findComment-1170907 Share on other sites More sharing options...
koo_04 Posted February 8, 2011 Author Share Posted February 8, 2011 How should I go about using it? Replace it with glob()? Link to comment https://forums.phpfreaks.com/topic/226933-removing-the-file-path-when-using-glob/#findComment-1171256 Share on other sites More sharing options...
requinix Posted February 8, 2011 Share Posted February 8, 2011 You "go about using it" only after you've read the manual. Link to comment https://forums.phpfreaks.com/topic/226933-removing-the-file-path-when-using-glob/#findComment-1171261 Share on other sites More sharing options...
koo_04 Posted February 8, 2011 Author Share Posted February 8, 2011 I wouldn't of posted it again if I didn't read and try to apply it. I get nothing out of it. Some ways I have tried it, it even breaks the webpage. :-\ Link to comment https://forums.phpfreaks.com/topic/226933-removing-the-file-path-when-using-glob/#findComment-1171264 Share on other sites More sharing options...
kenrbnsn Posted February 8, 2011 Share Posted February 8, 2011 Try <?php $dir = "/downloads/"; $files = glob($dir."*.zip", GLOB_NOSORT); echo'<select name="Files">'; foreach($files as $file){ echo'<option value="'.$file.'">'.basename($file).'</option>'; } echo'</select>'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/226933-removing-the-file-path-when-using-glob/#findComment-1171282 Share on other sites More sharing options...
koo_04 Posted February 8, 2011 Author Share Posted February 8, 2011 Thanks a ton. Now I need to just make a button that will download the selected file from the list. Link to comment https://forums.phpfreaks.com/topic/226933-removing-the-file-path-when-using-glob/#findComment-1171517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.