Recommended: How to use ASP programs to determine whether there are files on a disk The following is the quoted content: <%dim objfolderdim objfsodim j set fso=server.CreateObject(scripting.filesystemobject&q
I encountered such a problem when using ASP to create web pages for a certain unit. In the previous MIS system of the unit, some Word files were saved in the database in the form of byte streams. Now the user asked me to use ASP to take out these Word file data from the database and display them in the web page. At first, I naturally thought of creating a temporary file on the server and then adding a link to the temporary file to the web page. However, this method will greatly increase the burden on the server, and how to ensure that the temporary files used by a specific client are not overwritten by the files used by other clients on the service, and how to delete the files after the file is transferred to the user. These problems are actually difficult to solve. So is there a better way?
--- For this reason, I carefully looked at the ASP reference book and found that the Response object has a property called contenttype, which defines the MIME type of content sent to the client by the server. MIME's full name is Multipurpose Internet Mail Extensions, which is multi-function Internet mail extension. We know that in web programming, we sometimes point a hyperlink to a Word or Excel file. When the user clicks on this link, the browser will automatically call the corresponding method to open the file. The reason why this can be done is that after installing Office on the user's machine, the corresponding MIME resource type will be registered in the browser. For example, the MIME type of a word file is Application/msword (the former is MIME type and the latter is a MIME subclass), and the MIME resource type of an Excel file is Application/msexcel. In fact, all resources that can be processed by a browser have corresponding MIME resource types. For example, the MIME type of the html file is Text/html, and the MIME type of the JPG file is Image/JPG. In interaction with the server, the browser determines what kind of processing to be performed based on the MIME type of the data received, opens it directly for file browsers such as html and JPG, and calls the corresponding method to open files that cannot be opened by browsers such as Word and Excel. For files that are not marked with MIME type, the browser guesses its type based on its extension and file content. If the browser can't guess it, use it as an application/octet-stream. To understand the MIME types of various files, please check it in win98 My Computer -> View -> Folder Options -> File Type.
---- So I had a sudden inspiration and thought that in ASP, I could first take out WORD data in byte stream, then mark its contenttype attribute as Application/msword, and then send it to the client. After the client receives this resource, it will automatically call Word on the client according to its MIME type (of course, the premise is that Word is installed on the client, otherwise it will be used as an unrecognized resource and prompt the user to save it instead of opening it) to open it. The test results are very good, the method is simple and fast, and in IE 5, the browser uses embedded method (similar to OLE method), which has better results. The following is the program content.
--- Suppose the table name is tab_word, and there are two fields in the table. One is an integer type and an id, which is used as the unique identifier of Word data. The other is a blob type and a worddata, which stores Word data. Now to display the contents of Word file with id equal to 1 on the page, the ASP program is as follows:
| <% ' conn - Created database connection ' rs -- result set rs = conn.execute(select worddata from tab_word where id = 1) response.contenttype = Application/msword response.writebinary(rs(worddata)) 'Note that the data in the result set is sent directly using writebinary, and do not use variables 'Receive this data, otherwise the system will report an error % > |
Share: Fault resolution: How to solve the timeout of ASP script running I'm learning server knowledge recently. Sometimes I encounter an error in which the asp script runs timeout, which is really troublesome. I found relevant information, and there are some solutions. The default script timeout of IIS is 90 seconds. If you upload software or transfer data more than 90 seconds.