Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

How to select file from server as an input?

4:54 pm on Sep 13, 2012 (gmt 0)

New User

joined:Sept 13, 2012
posts: 2
votes: 0


I have on my server some big and scary piece of html/php code which analyses audio files. Basically user has to select .wav file from his own disc and upload it. I'm using good old <input name=... type="file"> to manage it.

Now, the problem is: I'd like to give the user possibility to select file to analyse directly from the server, from specified location (let's say /home/mine/www/wav/ - I mean the audio files has already been sent to the server, I just want the user to be able to select them to analysis, not files from his own PC). How to do it? Is there some sort of hidden option in <input...> or is it considered as "security risk" and can't be done?
5:36 pm on Sept 13, 2012 (gmt 0)

Full Member

10+ Year Member

joined:Feb 4, 2004
votes: 0

Don't use <input ...> for this because that would mean that the user first has to download the file to his PC and the upload it again to your server. If you only have a few files from which the user may choose list them on a page and the user may click on the file to analyse. If you have many files, you may sort them e.g. alphabetically with one page per letter.
10:56 pm on Sept 13, 2012 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 61

welcome to WebmasterWorld, kijciwoko!

you will have to provide the selection list for the visitor.
there is nothing native in a browser that can look at the filesystem on your server.
2:19 pm on Sept 14, 2012 (gmt 0)

New User

joined:Sept 13, 2012
posts: 2
votes: 0

Thanks for your answers. Just in case anyone else would need that, I managed to do it with this little trick in php:

$dir = '/some/directory/path/'; 
if (!isset($_POST['submit'])) {
if ($dp = opendir($dir)) {
$files = array();
while (($file = readdir($dp)) !== false) {
if (!is_dir($dir . $file)) {
$files[] = $file;
} else {
exit('Directory not opened.');
if ($files) {
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
foreach ($files as $file) {
echo '<input type="checkbox" name="files[]" value="' . $file . '" /> ' .
$file . '<br />';
echo '<input type="submit" name="submit" value="submit" />' .
} else {
exit('No files found.');
} else {
if (isset($_POST['files'])) {
foreach ($_POST['files'] as $value) {
echo $dir . $value . '<br />';
} else {
exit('No files selected');

from: [board.phpbuilder.com ] (don't know why the code isn't properly formatted here),

combined with this: [stackoverflow.com ]

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members