Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-06-2006, 03:57 PM   PM User | #1
freel0ader
New to the CF scene

 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
freel0ader is an unknown quantity at this point
Help with an upload script

Hi All,

I need some help with an upload script I am trying to use for my site. I am new to ASP, and I need this script to work a little diferently than it does. I was designed to save all the files you upload to the same folder in the directory. What I need it to do is save files from diferent form inputs to seperate folders on the server. Any help would be greatly appreciated.

<%@ Language=VBScript %>

<!-- #include file="freeaspupload.asp" -->
<%

Dim uploadsDirVar
uploadsDirVar = "e:\web\realequityh\htdocs\_images\large_images"

Dim uploadsDirVar
uploadsDirVar = "e:\web\realequityh\htdocs\_images\thumb_images"

function OutputForm()

%>

<%
end function

function TestEnvironment()
Dim fso, fileName, testFile, streamTest
TestEnvironment = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(uploadsDirVar) then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
fileName = uploadsDirVar & "\test.txt"
on error resume next
Set testFile = fso.CreateTextFile(fileName, true)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
Err.Clear
testFile.Close
fso.DeleteFile(fileName)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
exit function
end if
Err.Clear
Set streamTest = Server.CreateObject("ADODB.Stream")
If Err.Number<>0 then
TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
exit function
end if
Set streamTest = Nothing
end function

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 = ""
for each fileKey in Upload.UploadedFiles.keys

next
else
SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
end if

end function
%>


<HTML>
<HEAD>
<TITLE>Test Free ASP Upload</TITLE>

<script>
function onSubmitForm() {
var formDOMObj = document.frmSend;
if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" )
alert("Please press the browse button and pick a file.")
else
return true;
return false;
}
</script>

</HEAD>

<BODY>

<%
Dim diagnostics
if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
diagnostics = TestEnvironment()
if diagnostics<>"" then
response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
response.write diagnostics
response.write "<p>After you correct this problem, reload the page."
response.write "</div>"
else
response.write "<div style=""margin-left:150"">"
OutputForm()
response.write "</div>"
end if
else
response.write "<div style=""margin-left:150"">"
OutputForm()
response.write SaveFiles()
response.write "<br><br></div>"
end if

%>



<form name="frmSend" method="POST" enctype="multipart/form-data" action="" onSubmit="return onSubmitForm();">
<B>File names:</B><br>
File 1: <input name="attach1" type="file" size=35><br>
File 2: <input name="attach2" type="file" size=35><br>

<br>
<input style="margin-top:4" type=submit value="Upload">
</form>

</BODY>
</HTML>


Thanks,


-Adam
freel0ader is offline   Reply With Quote
Old 12-06-2006, 04:37 PM   PM User | #2
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
You declared a variable twice by accident.

Dim uploadsDirVar
uploadsDirVar = "e:\web\realequityh\htdocs\_images\large_images"

Dim uploadsDirVar
uploadsDirVar = "e:\web\realequityh\htdocs\_images\thumb_images"
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 12-06-2006, 07:33 PM   PM User | #3
freel0ader
New to the CF scene

 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
freel0ader is an unknown quantity at this point
Ya,

That is just where I was trying to creat a variable for the other file path. ahould look more like this.

Dim uploadsDirVar
uploadsDirVar = "e:\web\realequityh\htdocs\_images\large_images"

Dim uploadsDirVar2
uploadsDirVar2 = "e:\web\realequityh\htdocs\_images\thumb_images"

Still, I thing where I need to make the change to make it work is in this block of code.

function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey

Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)

I need to to make it look something like this.

If x
Upload.Save(uploadsDirVar)
then

If y
Upload.Save(uploadsDirVar2)

Its just that I cat look at the form with DOM in ASP, like I can with Javascript.

How do I get ASP to look at the input and see if the file is comming from attach1, or attach2?

Thanks,

-Adam
freel0ader is offline   Reply With Quote
Old 12-06-2006, 10:43 PM   PM User | #4
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
From what I can tell from their docs, you can't do this.
You may want to contact them for support. Their object appears to handle it as an all or nothing save.

http://www.freeaspupload.net/freeasp...umentation.asp


FreeASPUpload quick Reference

Main class FreeASPUpload

Public properties:

UploadedFiles - A Dictionary of UploadedFile objects. You can check the length of keys to verify if the user actually uploaded any files; see example in the SaveFiles function of the uploadTester.asp code sample.

Files - Equivalent to: UploadedFiles.Items . The SaveFiles function in uploadTester.asp provides an example of how to loop over the Files array to get access to all file descriptions.

Form - A collection with the values of the form elements posted by the upload form. This collection is empty until the Save method is called.

Public methods:

Save(upload directory path) - Saves all the uploaded files to the specified directory using same names the files had in the origin.
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 12-07-2006, 01:48 AM   PM User | #5
Baleric
Regular Coder

 
Baleric's Avatar
 
Join Date: Feb 2005
Location: Australia
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Baleric is an unknown quantity at this point
to get the value from a textfield use upload.form("") just like you would do request.form("")

but only use upload.form before the function upload.save is called,
then you can use an if statement on your directory at the top of your page

Code:
Dim uploadsDirVar

if upload.form("attach1") <> "" and upload.form("attach2") = "" then 
'attach2 is empty and attach1 is full

uploadsDirVar = "e:\web\realequityh\htdocs\_images\large_images"

else
end if

if upload.form("attach1") = "" and upload.form("attach2") <> "" then 
'attach1 is empty and attach2 is full

uploadsDirVar = "e:\web\realequityh\htdocs\_images\thumb_images"

else
end if
this way when attach1 is used it makes the first directory if attach2 form is used to call the script it changes to the second directory

Hope this is what you needed

let us know if it helped, ive had alot of problems with this script and it can get annoying!

Last edited by Baleric; 12-07-2006 at 01:58 AM..
Baleric is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:18 PM.


Advertisement
Log in to turn off these ads.