Jump to content

removing the file path when using glob()


koo_04

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.