Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP functionlity - basic structure

Status
Not open for further replies.

incron

Technical User
Mar 16, 2002
60
0
0
US
Guys I new to asp – and I’m somewhat confused – below is a code snippet from free asp upload:











<%@ Language=VBScript %>
<%
option explicit
Response.Expires = -1
Server.ScriptTimeout = 600
' All communication must be in UTF-8, including the response back from the request
Session.CodePage = 65001
%>
<!-- #include file="freeaspupload.asp" -->
<%


' ****************************************************
' Change the value of the variable below to the pathname
' of a directory with write permissions, for example "C:\Inetpub\ ' ****************************************************

Dim uploadsDirVar
uploadsDirVar = "d:\inetpub\webmailasp\database\tempUploads"


' Note: this file uploadTester.asp is just an example to demonstrate
' the capabilities of the freeASPUpload.asp class. There are no plans
' to add any new features to uploadTester.asp itself. Feel free to add
' your own code. If you are building a content management system, you
' may also want to consider this script:
function OutputForm()
%>
<form name="frmSend" method="POST" enctype="multipart/form-data" accept-charset="utf-8" action="uploadTester.asp" onSubmit="return onSubmitForm();">
<B>File names:</B><br>
File 1: <input name="attach1" type="file" size=35><br>
File 2: <input name="attach2" type="file" size=35><br>
File 3: <input name="attach3" type="file" size=35><br>
File 4: <input name="attach4" type="file" size=35><br>
<br>
<!-- These input elements are obviously optional and just included here for demonstration purposes -->
<B>Additional fields (demo):</B><br>
Enter a number: <input type="text" name="enter_a_number"><br>
Checkbox values: <input type="checkbox" value="1" name="checkbox_values"> 1 &nbsp;&nbsp;<input type="checkbox" value="2" name="checkbox_values"> 2<br>
Drop-down list (with multiple selection): <br>
<select name="list_values" class="TextBox" MULTIPLE>
<option value='frist' > First</option>
<option value='second' > Second</option>
<option value='third' > Third</option>
</select><br>
<textarea rows="2" cols="20" name="t_area">Test text area</textarea><br>
<!-- End of additional elements -->
<input style="margin-top:4" type=submit value="Upload">
</form>
<%
end function
end function

function TestEnvironment()
Dim fso, fileName, testFile, streamTest
TestEnvironment = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(uploadsDirVar) then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
fileName = uploadsDirVar & "\test.txt"
on error resume next
Set testFile = fso.CreateTextFile(fileName, true)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
Err.Clear
testFile.Close
fso.DeleteFile(fileName)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
exit function
end if
Err.Clear
Set streamTest = Server.CreateObject("ADODB.Stream")
If Err.Number<>0 then
TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
exit function
end if
Set streamTest = Nothing
end function

function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey

Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)

' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function

SaveFiles = ""
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
SaveFiles = "<B>Files uploaded:</B> "
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
next
else
SaveFiles = "No file selected for upload or the file name specified in the upload form does not correspond to a valid file in the system."
end if
SaveFiles = SaveFiles & "<br>Enter a number = " & Upload.Form("enter_a_number") & "<br>"
SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_values") & "<br>"
SaveFiles = SaveFiles & "List values = " & Upload.Form("list_values") & "<br>"
SaveFiles = SaveFiles & "Text area = " & Upload.Form("t_area") & "<br>"
end function
%>




















I thought everything in asp should be in the <% %> tags. Notice how the function is written. Am I not understanding the basic structure of Asp? Shouldn’t that function declaration be inside the asp tag? And notice there starting another function right after that. Can someone (from a coding standpoint) explain what’s happening here.
 
Take a simple example
Code:
<%@ Language=VBScript %>
<% 
option explicit 
dim now
now = date
function OutputForm()
%>
    <form name="frmSend" method="POST">
    <B>File names on <% now %> :</B><br>
    File 1: <input name="attach1" type="file" size=35><br>
    </form>
<%
end function
%>
This is the same as
Code:
<%@ Language=VBScript %>
<% 
option explicit 
dim now
now = date
function OutputForm()
   with response
      .writeline "<form name=""frmSend"" method=""POST"">"
      .writeline "<B>File names on " & cstr(now) & " :</B><br>"
      .writeline "File 1: <input name=""attach1"" type=""file"" size=35><br>"
      .writeline "</form>"
   end with
end function
%>
Is that any clearer?
 
Sorry - bad example: I was in a different language. Now is a built in function in vbscript
Code:
<%@ Language=VBScript %>
<% 
option explicit 
dim timenow
timenow = now
function OutputForm()
%>
    <form name="frmSend" method="POST">
    <B>File names on <% cstr(timenow) %> :</B><br>
    File 1: <input name="attach1" type="file" size=35><br>
    </form>
<%
end function
%>
Code:
<%@ Language=VBScript %>
<% 
option explicit 
dim timenow
timenow = now
function OutputForm()
   with response
      .writeline "<form name=""frmSend"" method=""POST"">"
      .writeline "<B>File names on " & cstr(timenow) & " :</B><br>"
      .writeline "File 1: <input name=""attach1"" type=""file"" size=35><br>"
      .writeline "</form>"
   end with
end function
%>
 
xwb - thanks for your quick reply.

So in the first example everything that was not ASP language source was placed outside of the tags and then the form was written even though it was between the two tags (and outside the ASP container) it is still part of the ASP function.


Then in the second example you put everything between ASP tags and converted the form to ASP code by using the response.write() function. _ am I correct...??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top