I am new to asp and sql. I have a job to do and with limited understanding of the way I need to gain the logic. I have and old upload form using aspUpload and now moving to FreeAspUpload. The form collects information for a small classifieds, form data written to sql database, display information drawn from DB, file attachments written to web folder according to date of upload. If you think you are able to assist me - let me know.
ASPWeb Languages and StandardsMicrosoft SQL Server
Last Comment
Surone1
8/22/2022 - Mon
Surone1
i assume you are new to the site? think of us as a bunch of code buddies. only you need to ask the right questions. or supply us with more information. (the thing you have trouble understanding, the lines in your code dealing with aspupload that need to be changed, or the lines where you get errors ) it may not be wise to post too much of your code for security reasons.
There is a upload function page and a freeASP Upload file.
I need the Attachments to be uploaded into a folder which is name by the current date.
AI have checked errors and get as far as outputing the string I am lookiing for but I cannot upload. I am missing something.
Go easy on me - I am new to this
(I have commented out the sql stuff for the moment - I will worry abou that later) freeaspupload.txt
Surone1
i just installed ASP.NET and by the looks of it this is classic asp code. so i will have to install that if i can. but it's late for me now. so i'll get back on this tomorrow if nobody else jumps in.
ok i just got things working on my end after playing around with the testupload.asp they include in the zip file :
i did create a directory "c:\testupload" and gave write permission to IUSR
then i took the lines of code we needed from the example and pasted that into the source:
<%@ Language=VBScript %>
<%
'On Error Resume Next
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"-->
<%
Dim uploadsDirVar
uploadsDirVar = "c:\testupload"
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
response.write SaveFiles()
response.write "<br>end<br>"
response.end
'this uploaded the file without any problems
vis-66
ASKER
I am able to upload a file as well - this is what I need the code to do:
I have a date field - I need the date field to become the name of folder to contain each uploaded attachment - I think I am missing some code to enable me to create the folder object. Did you see my attachments?
Thanks in advance
Surone1
as far as i can tell the upload directory would need to exist for this script to work., so you would need a way to create the directory before setting the uploadsDirVar to it.
I need to create a directory on the fly - is there no way?
The previous code that was used for this project used the date as a string which then became the folder name. If there was an existing folder a folder would not be generated but the attachment would then be uploaded to the existing folder. If a folder was needed the date would be used as the new generated folders name and the attachment then uploaded.
What are my chances in adapting the code I have attached?
Surone1
pretty good?
have a look at the link above, it contains an example of how to create a directory. you probably want to fix the types of the variables before pasting it in your code since your code has "option explicit" turned on.
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(uploadsDirVar) Then
Set newfolder = filesys.CreateFolder(uploadsDirVar)
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
currently just without a development platform. I do develop some asp.net in MS VS 10 but the classic asp just handcoded without a platform in WYSIWYG editor (Adobe DW)
vis-66
ASKER
I have tried the attached code - this is it! I am getting an internal 500 error (doesnt tell me much)
When I break the code in the middle I have the correct output but it will not allow me to create the file.
'Response.Write("A new folder has been created at: " & uploadsDirVar)
' response.end()
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(uploadsDirVar) Then
Set newfolder = filesys.CreateFolder(uploadsDirVar)
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
%>
Surone1
<%
on error goto hell
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds/attachments/" + post_date
'Response.Write("A new folder has been created at: " & uploadsDirVar)
' response.end()
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(uploadsDirVar) Then
Set newfolder = filesys.CreateFolder(uploadsDirVar)
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
response.end
hell:
response.write err.number & " - " & err.description
%>
set filesys=CreateObject("Scripting.FileSystemObject")
If Not filesys.FolderExists(snewfolder) Then
'response.Write("Folder doesn't exists")
' response.end()
Set newfolder = filesys.CreateFolder(snewfolder)
' Response.Write("A new folder has been created at: " & snewfolder)
' response.end()
Else
' response.Write("Folder exists")
' response.end()
End If
vis-66
ASKER
I have one final issue with my code - I have a database with a time stamp field. I have a variable named today which is equals 'now'. I know my date/time string is incorrect but I am not sure how I need to format it
Creating a directory on the fly with aspfreeupload using a date field as the folder name so folders and items may be ordered by date in its final transending into a Database
the thanks suggests the asker was helped somehow.
---
back to the second question here DatePart("mm",Date) will give you the month. not minutes.
us DatePart("nn",Date) for minutes
Surone1
sorry pressed submit instead of object in the above post.