Click to See Complete Forum and Search --> : Upload file to directory...how?


Calmaris
12-30-2003, 05:05 PM
Ok I've figured out how to create a directory based on the user logged in..but I can't get the file to be uploaded to that directory! I need someone to "Lend" me some code that my limited knowledge can modify and I'll understand. Thx in advance.

<%@ Page Language="VBScript" Debug="true" aspcompat=true %>
<%


Dim fileSys, newFolderStr, newFolder, newUsername
fileSys = Server.CreateObject("Scripting.FileSystemObject")

newUsername = request.form("User_Id")


newFolderStr = "C:\pics\members\ " & newUsername & " "

If Not fileSys.FolderExists(newFolderStr) Then

newFolder = fileSys.CreateFolder(newFolderStr)

End If


%>
User Id: <%response.write(newUsername)%>

PeOfEo
12-30-2003, 06:46 PM
I have some file upload scripts, but they are in asp.net. http://forums.webdeveloper.com/showthread.php?s=&threadid=23456

Calmaris
12-30-2003, 08:39 PM
It won't let me do a request within the server script below too access the user id. The user's Id will be the new folder the picture will be inserted into. How can I pass this value? without an error?

<%@ Page Language="VB" Debug="true"%>

<%
Dim newUsername
userid = request.querystring("User_Id")%>

<script runat="server">
dim userid
Dim newUsername = userid
'DIM newUsername = request.querystring("User_Id")

Sub uploadit (Sender as Object, e as EventArgs)
Dim strFileName as string
strFileName = theFile.PostedFile.FileName
Dim theFileName as string = System.IO.Path.GetFileName(strFileName)

Try
theFile.PostedFile.SaveAs("C:\pics\members\ " & newUsername &" ") 'Be sure to change this path for your dir!
successful.visible= true
catch Exp as exception
woops.Visible = true
End Try
End Sub


</Script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>
Simple Upload form
</title>
</head>
<body>
<form method="Post" enctype="Multipart/Form-Data" runat="Server">
Select a file to upload:

_ USER ID

<% response.write(userid)%>
<input id="theFile" type="File" runat="Server" size="30">
<br><br>
<input type="Submit" value="Upload" onserverclick="uploadit" runat="Server">
<asp:label id="successful" runat="server" visible="false">
Your upload was a sucesses!
</asp:label>
<asp:panel id="woops" runat="server" Visible="False">
Your File upload failed.
</asp:panel>
</form>
</body>
</html>

PeOfEo
12-31-2003, 12:20 AM
why are you doing it out of a sub, you should put it all inside of the sub I think, if you are only using one sub it would run smoother, or put an onload sub. Also if they are session variables, the user id, why are you putting it in a query string. request.session("memberid")

Calmaris
12-31-2003, 12:38 AM
Well I can't think of any other way to make the session(memberId) = to the user's id. I'll try the other advice, though thx...is there anyother way to get the session Id = to the member's Id...I'm all out of Ideas. THx in advance

PeOfEo
12-31-2003, 01:37 AM
you have to request it. Like a query string or server variable
request.session("id")
request.querystring("key")
request.servervariablea("remote_addr")

Calmaris
12-31-2003, 05:52 PM
This is the Error I'm getting. why isn't request.session a member of the httpRequest?
Is this how I can replace the contents of session(ID)
session("ID") = ( User_Id ) and if I can could I access that from any page, especially in the server scripts in my upload.aspx? Thx in Advance

Compiler Error Message: BC30456: 'session' is not a member of 'System.Web.HttpRequest'.

Source Error:



Line 31:
Line 32:
Line 33: request.session("id")
Line 34: request.querystring("key")
Line 35: request.servervariablea("remote_addr")


Source File: c:\inetpub\wwwroot\mess\Logged_Home.aspx Line: 33




<%@ Page Language="VBScript" Debug="true" aspcompat=true %>

<%


Dim query conn, dbQuery, rs, User_Id, Password, recordsetDB,,query3
Dim old_User_Id, query2,online, useronline,userid, usernames, query1, makeonline

User_Id = request.form("User_Id")
Password = request.form("Password")

conn = Server.CreateObject("ADODB.Connection")
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\wwwroot\mess\databases\Members.mdb")

query = "SELECT * " & _
"FROM Members " & _
"WHERE User_Id = " &" '" & User_Id & "' AND Password = " &" '" & Password & "' "
rs = conn.execute(query)

if rs.eof then
response.redirect("No_User.html")
end if

if NOT rs("user_Id").value is ("Admin") AND rs("Password").value is ("Mess") THEN
response.redirect("Admin.asp")
end if


request.session("id")
request.querystring("key")
request.servervariablea("remote_addr")
session("ID") = ( User_Id )

query1 = " UPDATE Members SET offlinenow = False WHERE offlinenow = True AND User_Id = '" & User_Id & "' "
conn.execute(query1)

Dim Timenow = Now()
query3 = " UPDATE Members SET Login_Time = Now() WHERE User_Id = '" & User_Id & "' "
conn.execute(query3)

useronline = "Yes"
query2 = " SELECT User_Id FROM Members WHERE offlinenow = False "
online = conn.execute(query2)
%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Logged_Home</title>
</head>
<body>


Who is logged on: <%
DO WHILE NOT online.EOF
recordsetDB = server.createObject("ADODB.recordset")
recordsetDB.Open (online)
response.write (online ("User_Id").value)
response.write(",")
online.MoveNext
Loop
%>
<br>
<br>

<br>
THIS wILL BE THE MAIN PAGE!
What session is carrying: <%response.write (session("memberID")) %>
<br></br>
<p>
<%
response.write("You Are " & Application("Numsession") & " OF " & Application ("NumVisited") & " Users")
%>
This is rs: <%response.write (query) %><br><p>
This is if you are logged on: <%
If (rs("offlinenow").value) = False Then
response.write("True")
else
response.write("False")
end if

'response.write(rs("offlinenow").value) %>

<form NAME="Update" METHOD="POST" ACTION="Update_Member_Reg.aspx">


UPDATE YOUR MEMBER INFO<p>User ID<input Name="User_Id" SIZE="20" MAXLENGTH="20" value="<%=session("member")%>"> </td>
Password<input TYPE="PASSWORD" NAME="Password" SIZE="20" MAXLENGTH="20">

<input type="submit" value="Submit" name="Update_Button"> </p>
</form>
<form method="POST" enctype="multipart/form-data" action="Upload.aspx">
<input Name="User_Id" TYPE="Hidden" SIZE="20" MAXLENGTH="20" value="<%=User_Id%>">


<p><input type="file" name="File" size="20">
<input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>

THE USER ID BEING PASSED: <%response.write(User_Id)%>
<p><a href="log_Out.aspx?User_ID=<% response.write(User_Id)%> " >Log Off</a></p>
<p><a href="View_Members.aspx">View who has signed up!</a></p>
<p><a href="Chat/Default.asp">Go and chat!</a></p>
<p><a href="Upload.aspx?User_ID=<% response.write(User_Id)%> " >Upload a pic</a></p>
</body>
</html>

PeOfEo
01-01-2004, 02:54 AM
agh... sorry major brain fart. Oh man. its just
session("id")
sorry
:(

Calmaris
01-02-2004, 04:00 PM
Ok so with those 3 lines I can create another session variable that I will be able to change whatever it is to the user's Id, and I will be able to access that variable in session on another page? and should I still use session("id") = User_Id to make it the user's logon Id? Also can I access that in a server script?

Calmaris
01-03-2004, 09:06 PM
I figured it out.