File+Operations

toc =Upload= To upload a file to the server, use the **UPLOAD** command. It requires a string variable to contain the name of the uploaded file. It looks like this: code upload "Choose a file to upload:"; fname$ code The user is presented with a BROWSE button and an UPLOAD button. It looks like this:



After he presses the BROWSE button and selects a file, the name of the file appears in the textbox. He can then press the UPLOAD button to upload it to the server. It can be accessed with the filename you've given it in the UPLOAD command.



=Open= The file is accessed with the name given in the UPLOAD command. It is opened for input like this: code open fname$ for input as #file code

=Input - Line Input= To input information from an uploaded file, you can use LINE INPUT or INPUT. Here's an example of LINE INPUT. LINE INPUT retrieves data up to a carriage return. code while eof(#file) = 0 line input #file, var$ print var$ wend code

This one uses INPUT. Input retrieves data up to the next comma or carriage return. Try both to see the difference.

code while eof(#file) = 0 input #file, var$ print var$ wend code

These examples simply print out the retrieved data. Your program can act on the data in other ways.

=Close= Close the file when it is no longer needed. code close #file code

=Demo= Here's a complete demo that asks the user to upload a file, then retrieves the data and displays it to the user. code upload "Choose a file to upload:"; fname$

open fname$ for input as #file while eof(#file) = 0 line input #file, var$ print var$ wend close #file end code