| How to select file from server as an input?
|
kijciwoko

msg:4494795 | 4:54 pm on Sep 13, 2012 (gmt 0) | Hi!
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?
|
adb64

msg:4494812 | 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.
|
phranque

msg:4494930 | 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.
|
kijciwoko

msg:4495195 | 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; } } closedir($dp); } 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" />' . '</form>'; } 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 ]
|
|
|