vis-66
asked on
HELP - Need a code Buddy
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.
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.
ASKER
fileupload-code.txtform-code.txt Thanks.
I have attached the files that are involved.
There is a regular form with ordinary fields.
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
I have attached the files that are involved.
There is a regular form with ordinary fields.
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
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(fileK ey).FileNa me & " (" & Upload.UploadedFiles(fileK ey).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_numbe r") & "<br>"
SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_valu es") & "<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
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(fileK
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_numbe
SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_valu
SaveFiles = SaveFiles & "List values = " & Upload.Form("list_values")
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
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
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
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.
this could help?
http://www.devguru.com/technologies/vbscript/quickref/filesystemobject_createfolder.html
this could help?
http://www.devguru.com/technologies/vbscript/quickref/filesystemobject_createfolder.html
ASKER
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?
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?
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.
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.
try this as a seperate page first.
<%
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds /attachmen ts/" + post_date
set filesys=CreateObject("Scri pting.File SystemObje ct")
If Not filesys.FolderExists(uploa dsDirVar) Then
Set newfolder = filesys.CreateFolder(uploa dsDirVar)
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
%>
<%
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds
set filesys=CreateObject("Scri
If Not filesys.FolderExists(uploa
Set newfolder = filesys.CreateFolder(uploa
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
%>
ASKER
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)
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.
<%
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds /attachmen ts/" + post_date
'Response.Write("A new folder has been created at: " & uploadsDirVar)
' response.end()
set filesys=CreateObject("Scri pting.File SystemObje ct")
If Not filesys.FolderExists(uploa dsDirVar) Then
Set newfolder = filesys.CreateFolder(uploa dsDirVar)
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
%>
When I break the code in the middle I have the correct output but it will not allow me to create the file.
<%
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds
'Response.Write("A new folder has been created at: " & uploadsDirVar)
' response.end()
set filesys=CreateObject("Scri
If Not filesys.FolderExists(uploa
Set newfolder = filesys.CreateFolder(uploa
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
%>
<%
on error goto hell
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds /attachmen ts/" + post_date
'Response.Write("A new folder has been created at: " & uploadsDirVar)
' response.end()
set filesys=CreateObject("Scri pting.File SystemObje ct")
If Not filesys.FolderExists(uploa dsDirVar) Then
Set newfolder = filesys.CreateFolder(uploa dsDirVar)
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
response.end
hell:
response.write err.number & " - " & err.description
%>
on error goto hell
dim filesys, newfolder
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds
'Response.Write("A new folder has been created at: " & uploadsDirVar)
' response.end()
set filesys=CreateObject("Scri
If Not filesys.FolderExists(uploa
Set newfolder = filesys.CreateFolder(uploa
Response.Write("A new folder has been created at: " & uploadsDirVar)
End If
response.end
hell:
response.write err.number & " - " & err.description
%>
ASKER
No luck - only an internall 500 error - no error or error number
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Changed up my code
Found out what one of my problem were- hadnt fixed one of my variables (snewfolder) adn hadnt mapped my variable to the server.
Thanks everyone. I will be back with some new problems as I move towards entering this data now to the sql server - more fun
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds /attachmen ts/" + post_date
snewfolder = server.mapPath(uploadsDirV ar)
' Response.Write(snewfolder)
' response.end()
set filesys=CreateObject("Scri pting.File SystemObje ct")
If Not filesys.FolderExists(snewf older) Then
'response.Write("Folder doesn't exists")
' response.end()
Set newfolder = filesys.CreateFolder(snewf older)
' Response.Write("A new folder has been created at: " & snewfolder)
' response.end()
Else
' response.Write("Folder exists")
' response.end()
End If
Found out what one of my problem were- hadnt fixed one of my variables (snewfolder) adn hadnt mapped my variable to the server.
Thanks everyone. I will be back with some new problems as I move towards entering this data now to the sql server - more fun
post_date = DatePart("yyyy",Date)& DatePart("m",Date) & DatePart("d",Date)
uploadsDirVar = "/staff/portal/classifieds
snewfolder = server.mapPath(uploadsDirV
' Response.Write(snewfolder)
' response.end()
set filesys=CreateObject("Scri
If Not filesys.FolderExists(snewf
'response.Write("Folder doesn't exists")
' response.end()
Set newfolder = filesys.CreateFolder(snewf
' Response.Write("A new folder has been created at: " & snewfolder)
' response.end()
Else
' response.Write("Folder exists")
' response.end()
End If
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
Any answers?
Any answers?
that would actually be a new question i guess , but i can tell you you probably want to use the format function for it :-)
http://www.techonthenet.com/access/functions/date/format.php
http://www.techonthenet.com/access/functions/date/format.php
sorry i assumed asp has the format function. turns out it doesnt :-(
asp has formatdatetime. which is rather limited
http://www.powerasp.net/content/new/formating-date-and-time.asp
asp has formatdatetime. which is rather limited
http://www.powerasp.net/content/new/formating-date-and-time.asp
ASKER
apologies for entering a different question. I will create a new question next time.
the format for my sql database is set to US (unfortunately)
1900-01-01 00:00:00.000
my output
insert into staff_page_classifieds (title, body, name, phone, email, type, closed, owner, post_date, time_stamp, attachment) values ('TEST','test','vee','1123 4535','vee j@live.com .au','2',' ','jacobsv ','2012102 ','2/10/20 12','/staf f/portal/c lassifieds /attachmen ts/2012102 /adobe-ico ns.jpg')
I am not sure how to set the string for this output
the format for my sql database is set to US (unfortunately)
1900-01-01 00:00:00.000
my output
insert into staff_page_classifieds (title, body, name, phone, email, type, closed, owner, post_date, time_stamp, attachment) values ('TEST','test','vee','1123
I am not sure how to set the string for this output
db_date = DatePart("dd",Date) & "/" & DatePart("mm",Date) & "/" & DatePart("yyyy",Date)
or
db_date = DatePart("mm",Date) & "/" & DatePart("dd",Date) & "/" & DatePart("yyyy",Date)
or
db_date = DatePart("mm",Date) & "/" & DatePart("dd",Date) & "/" & DatePart("yyyy",Date)
ASKER
no - not working
I have include hours, minutes seconds as well
today=DatePart("yyyy",Date ) & "-" & DatePart("mm",Date) & "-" & DatePart("dd",Date)& DatePart("hh",Date)&":"& DatePart("mm",Date)&":"& DatePart("ss",Date)
I have include hours, minutes seconds as well
today=DatePart("yyyy",Date
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for vis-66's comment #a38449502
for the following reason:
This solution was not straight forward. The server map path was needed to create the new folder according to the aspfreeupload file.
Accepted answer: 0 points for vis-66's comment #a38449502
for the following reason:
This solution was not straight forward. The server map path was needed to create the new folder according to the aspfreeupload file.
ASKER
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
https://www.experts-exchange.com/questions/27878327/HELP-Need-a-code-Buddy.html?anchorAnswerId=38449502#a38449502
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
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
sorry pressed submit instead of object in the above post.
there is also no space between the year and hour parts in your code.
ASKER
Yes I think you are right JARmod101...I will assign to Surone1.
I found I needed a collective of info to get the code working but this was the most helpful.
Thanks everyone - most appreciated
I found I needed a collective of info to get the code working but this was the most helpful.
Thanks everyone - most appreciated
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for vis-66's comment #a38453252
for the following reason:
Date formatting has made the difference
Accepted answer: 0 points for vis-66's comment #a38453252
for the following reason:
Date formatting has made the difference
my reccomendation would be accept https://www.experts-exchange.com/questions/27878327/HELP-Need-a-code-Buddy.html?anchorAnswerId=38449502#a38449502 with https://www.experts-exchange.com/questions/27878327/HELP-Need-a-code-Buddy.html?anchorAnswerId=38449463#a38449463 as assisted solution
https://www.experts-exchange.com/questions/27878327/HELP-Need-a-code-Buddy.html?anchorAnswerId=38488107#a38488107 something probably went wrong.