homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

How to select file from server as an input?

Msg#: 4494793 posted 4:54 pm on Sep 13, 2012 (gmt 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?



10+ Year Member

Msg#: 4494793 posted 5:36 pm on Sep 13, 2012 (gmt 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.


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

Msg#: 4494793 posted 10:56 pm on Sep 13, 2012 (gmt 0)

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.


Msg#: 4494793 posted 2:19 pm on Sep 14, 2012 (gmt 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 ]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved