2

I have a website that asks the user to open a input file from his PC. This input file contains a lot of info. After opening the input file the user can click buttons and the website will search in the input file to display corresponding info.

It is a bit complex to create the input file. Therefore I want to give the possibility to test the website with an example file that is on the server. So the user can test the website before creating their own input file.

I have an example input file on the server.

How can I give the user the option to open a local input file, but also the example file from the server?

I use now (only local files):

Select your file:<input type="file" id="fileinput" />

Remark

It would also be ok for me if the user can open the example file via a button like <Open example file>.

j0k
  • 22,600
  • 28
  • 79
  • 90
user1798023
  • 95
  • 1
  • 2
  • 5
  • Thanks for the answers!! The website browser things look too much for what I want. Can I open one specific file (name hard coded) on the server that is in the same directory as my webpage? What command should I use for that. => Give user the option to open his own file from his PC or push a button to open the web server file. (...learning html and javascript, so excuse me if this is a basic question) – user1798023 Nov 04 '12 at 16:22

3 Answers3

3

When you say using input type=“file”, there is no such a way read a file on the server side, if you are coding B/S application, any file reading process need to be done on server end.

If you want user have some choices to read server file(on your server side), simply add a dropdown/checkbox list/radio button list what ever, make every choice reflect to one specific file on the server side, and then just read it on server end depends on which one selected.

The input type="file" will just be a post action to post the whole file to server end as well, you either store it on server end temp folder and parse it or read it directly from memory.

Simon Wang
  • 2,843
  • 1
  • 16
  • 32
1

You could use radio buttons:

<fieldset>
    <legend> input file <legend>
    <div>
        <label> <input type="radio" name="input_source" value="server"> Defaults </label>
    </div>
    <div>
        <label> <input type="radio" name="input_source" value="upload"> From file </label>
    </div>
    <div>
        <label> <input type="file" name="input_file"> Upload an input file </label>
    </div>
</fieldset>

Alternatively, just use the file on the server if no file is uploaded.

<label> <input type="file" name="input_file"> Upload an input file (leave blank for defaults) </label>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

<input type="file"> is only for uploading files. You can't browse server files with it.

You could use one of several web file browser scripts available, or write your own script to create that functionality, but it's not something that is available natively in HTML.

Can i browse file stored on Remote server through simple <input type="file"> control in asp.net MVC 2.0 - There are a few examples provided in the answer to this question, which is pretty close to yours.

Community
  • 1
  • 1
  • Thanks for the answers!! The website browser things look too much for what I want. Can I open one specific file (name hard coded) on the server that is in the same directory as my webpage? What command should I use for that. => Give user the option to open his own file from his PC or push a button to open the web server file. (...learning html and javascript, so excuse me if this is a basic question) – user1798023 Nov 04 '12 at 16:46