Store filename in a session variable
Question:
How can I store the filename of the uploaded file in a session variable?
I simply want the files to be uploaded and filenames stored in session variables, no need to insert in a database table.
Answer:
Storing the filenames in session variable is easy:
Session("filename1") = UploadFormRequest("filename1")
but you should do this only when the upload is in process so:
If (CStr(Request.QueryString("GP_upload")) <> "") Then
Session("filename1") = UploadFormRequest("filename1")
Session("filename2") = UploadFormRequest("filename2")
end if
Add this code at the end of the upload code
filename1 and filename2 are the form upload field name
Comments
Get Session Var
I can't get this code to work. Where exactly after the upload code do you put it? I have an upload page that redirects to a details page that displays the name of the file just uploaded.
I've been putting the code at the end:
...
else
if UploadQueryString <> "" then
UploadQueryString = UploadQueryString & "&GP_upload=true"
else
UploadQueryString = "GP_upload=true"
end if
end if
If (CStr(Request.QueryString("GP_upload")) <> "") Then
Session("PDFFileName") = UploadFormRequest("filename1")
end if
' End Pure Upload
'------------------------------------------------------------------------------
</SCRIPT>
And it is not setting the session variable. Any tips?
Thanks
UploadFormRequest + Manual Insert
I am having the same problem.
I can't seem to grab the filename nor any of my fields using the UploadFormRequest syntax. I don't use Dreamweaver MX's insert behavior (I hand write the SQL) and i am trying to store my field names in a session variable and pass them into a second page to insert them into a SQL DB.
How do you grab the form values in addition to the uploaded filename?
RE: Get Session Var
Robert,
I figured this one out. Throughout the UDZone site the continual message has been put the UploadFormRequest syntax below the 'End Pure Upload Comment.This is wrong, because using the redirect, the page redirects before the session variables are set.
Try Putting it above the redirect syntax. So putting it right here:
'PUT YOUR SESSION VAR DECLARATION HERE-----------------------
If (CStr(Request.QueryString("GP_upload")) <> "") Then
session("filename") = UploadFormRequest("file")
end if
'--------------------------------------------------------------------
If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("MM_insert")) <> "" or CStr(UploadFormRequest("MM_update")) <> "")) Then
If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
End If
Response.Redirect(GP_redirectPage)
end if
else
if UploadQueryString <> "" then
UploadQueryString = UploadQueryString & "&GP_upload=true"
else
UploadQueryString = "GP_upload=true"
end if
'------------------------
Form Submitting on the redirect
Is there a way to form.submit() after the upload has taken place instead of redirecting to a new page losing my form elements?
I am inserting quite a bit of data into a DB and can't afford the overhead of converting all my form element's values into session variables and then inserting them within that same page.
Please advise. Thanks.
You must me logged in to write a comment.