Forums

ASP

This topic is locked

Need help! Upload to organized folder

Posted 13 Mar 2009 14:46:30
1
has voted
13 Mar 2009 14:46:30 lowanda libero posted:
Dear all,

I kindly ask you to help me finding out what's wrong with my code.
I need to let the users of the private area of my website to upload files choosing the folder where to upload from a list box.
I have two files: upload.asp (containing the form) and saveupload.asp (containing the code).
In saveupload.asp at line 36 there is the destination path for the upload. I think the problem is there.
The destination folder is PRIVATE/UPLOAD, and in DOWNLOAD folder there are other folder as CONTRACTS and DRAFT. I would like the user to choose the folder from the dropdown menu list in the form.
Please could you help me?
Thank you in advance
Best Regards
Francesca


UPLOAD.ASP
<%@Language=VBScript%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="POST" enctype="multipart/form-data" action="saveupload.asp">
  <div align="center">
    <center>
    <table border="0" style="border-collapse: collapse" bordercolor="#111111" width="74%" id="AutoNumber1">
      <tr bgcolor="#66FF00">
        <td width="100%" colspan="2"><b><font face="Arial">File Upload</font></b></td>
      </tr>
      <tr>
        <td colspan="2"> </td>
      </tr>
      <tr>
        <td width="50%"><b><font face="Arial">Upload file </font></b></td>
        <td width="50%"><font face="Arial"><b>
        <input type="file" name="File1" size="20"></b></font></td>
      </tr>
      <tr>
        <td>Department</td>
        <td><select name="department" id="department">
          <option value="CONTRACTS">CONTRACTS</option>
          <option value="CRICKET">DRAFTS</option>
        </select></td>
      </tr>
      <tr>
        <td width="100%" colspan="2"><font face="Arial"><b>
        <input type="submit" value="Submit" name="B1"></b></font></td>
      </tr>
    </table>
    </center>
  </div>
</form>
</body>
</html>



SAVEUPLOAD.ASP
<%@Language=VBScript%>
<!--#INCLUDE FILE="upload.class"-->
<
%Dim oUpload
Dim oFile
Dim sFileName
Dim oFSO
Dim sPath
Dim sNewData
Dim nLength
Dim bytBinaryData


Const nForReading = 1
Const nForWriting = 2
Const nForAppending = 8

' grab the uploaded file data
Set oUpload = New clsUpload
Set oFile = oUpload("File1")

' parse the file name
sFileName = oFile.FileName
If Not InStr(sFileName, "\") = 0 Then
	sFileName = Mid(sFileName, InStrRev(sFileName, "\") + 1)
End If

' Convert the binary data to Ascii
bytBinaryData = oFile.BinaryData
nLength = LenB(bytBinaryData)
For nIndex = 1 To nLength
	sNewData = sNewData & Chr(AscB(MidB(bytBinaryData, nIndex, 1)))
Next

' Save the file to the file system
sPath = Server.MapPath("..\private\upload") & Request.Form("Department")
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
oFSO.OpenTextFile(sPath & sFileName, nForWriting, True).Write sNewData
Set oFSO = Nothing

Set oFile = Nothing
Set oUpload = Nothing
%>
<p>File has been saved in file system. </p>
<p> </p>
<p><a href="test2.asp">Go to files list </a></p>

Reply to this topic