Reply
Uploading to more than one directory?
Old 02-06-2008, 02:53 PM Uploading to more than one directory?
Super Talker

Posts: 115
I'm using freeASPupload and it works as it should. It uploads to the directory that I've chosen.

Is there a way to modify this script so that it can upload to more than one directory?

In other words, the first file gets uploaded to directory A, the next upload gets uploaded to Directory B, the next file gets uploaded to directory A again, the next file gets uploaded to directory B again, and so on.

Is this possible?

If so can you provide me with some guidance on how to accomplish this?
Here is the the uploadtester page code for your review. Thanks.

Code:
<%@ Language=VBScript %>
<%
'option explicit
Response.Expires = -1
Server.ScriptTimeout = 600
%>
<!--#include virtual="aspUpload.asp" -->
<%

' ****************************************************
  Dim uploadsDirVar
  uploadsDirVar = "C:/DirectoryA/"
' ****************************************************
function OutputForm()
%>
    <form name="frmSend" method="POST" enctype="multipart/form-data" action="uploadTester.asp" onSubmit="return onSubmitForm();">
 <B></B><br><input name="attach1" type="file" size=35><br>
    <!--File 2: <input name="attach2" type="file" size=35><br>-->
    <!--File 3: <input name="attach3" type="file" size=35><br>-->
    <!--File 4: <input name="attach4" type="file" size=35><br>-->
    <br>
 <!-- These input elements are obviously optional and just included here for demonstration purposes -->
 <!--<B>Additional fields (demo):</B><br>-->
 <!--Enter a number: <input type="text" name="enter_a_number" size="20"><br>-->
    <!--Checkbox values: <input type="checkbox" value="1" name="checkbox_values">-1 <input type="checkbox" value="2" name="checkbox_values">-2<br>-->
 <!-- End of additional elements -->
    <input style="margin-top:4" type=submit value="Upload">
    </form>
<%
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.setMaxFileSize 0.5, "m"
    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 = "The file name specified in the upload form does not correspond to a valid file in the system."
    end if
 SaveFiles = SaveFiles & "" & Upload.Form("enter_a_number") & "<br>"
 SaveFiles = SaveFiles & "" & Upload.Form("checkbox_values") & "<br>"
end function
SUB updateDB_Logout
 Call OPEN_DB()
 MyConn.Execute( "UPDATE mms_tbl_user SET fldSTATUS = '" & drpSTATUS(5) & "' WHERE ID = " & Session("PMMS_ID") )
 IF Session("PMMS_IN") = "True" THEN
            Call APPEND_LOG(False, Session("PMMS_ID"), "Logs out.", Trim(sysVAL(7)))
        END IF
  MyConn.close
        Set MyConn = Nothing
  Session.Abandon
        Response.Redirect( "PPL_Logout.asp" )
        Response.end
END SUB
%>
 
<HTML>
<HEAD>
<Title>TEST</Title>
<style type="text/css">
body {margin: 1px 100px; padding: 1px; 0px}
</style>
</HEAD>
<BODY leftMargin=0 topMargin=0 marginheight="0" marginwidth="0"  body {border-left: 1px solid #000; }>
<SCRIPT LANGUAGE="JavaScript">errorcolor = '#eeeeee';</Script>
<table cellspacing=0 border=0 cellpadding=40 width=100% align=left>
 <tr>
  <td align=left valign=middle>
<script language="JAVASCRIPT">
 var errfound = false;
  function ValidLength(item, len) {
     return (item.length >= len);
  }
  function error(elem, text) {
     if (errfound) return;
     window.alert(text);
     elem.select();
     elem.focus();
     elem.style.backgroundColor=errorcolor;
     errfound = true;
  }
  function Validate() {
     errfound = false;
     d=document.login
     if (!ValidLength(d.members_username.value,1))error(d.members_username,"Username should not be blank.");
     if (!ValidLength(d.members_password.value,1))error(d.members_password,"Password should not be blank.");
     return !errfound;
  }
</script>
<TR valign=top>
<div style="border:0px solid #000000; width: 705px; padding-left: 75px; text-align:top;">

<style>
BODY {background-color: white;font-family:arial; font-size:12}
</style>
<script>
function onSubmitForm() {
    var formDOMObj = document.frmSend;
    if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" && formDOMObj.attach3.value == "" && formDOMObj.attach4.value == "" )
        alert("Please press the browse button and pick a file.")
    else
        return true;
    return false;
}
</script>
</HEAD>
<BODY>
<br><br>
<div style="border-bottom: #A91905 2px solid;font-size:16">1. Select(Click) the Browse Button<br>
2. Choose Your File For Uploading<br>
3. Select(Click) the Upload Button<br><br></div>
<%
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:5"">"
        OutputForm()
        response.write "</div>"
    end if
else
    response.write "<div style=""margin-left:5"">"
    OutputForm()
    response.write SaveFiles()
    response.write "<br><br></div>"
    IF PPL_GROUP_MEMBER = "Y" THEN
     updateDB_Logout
 end if
end if
%><img src="img/linkimg9.jpg" style="vertical-align: middle;" width="32" height="27" alt="" border="0" />
<span style="color: #FFFFFF"><%=Trim(Session("PMMS_EMAIL"))%>
</span>
<br><br>
</p></div></tr></td></tr>
</table></TD></TR><!--#include file="inc_footer.asp"--></TABLE>
  </TD>
 </TR>
</TABLE>
<TABLE cellSpacing=0 valign=bottom cellPadding=0 width=100% border=0>
 <TR valign=top height=4>
 </TR>
 <TR valign=middle height=25>
  <TD class=headera2>&nbsp;<FONT class=linksmall><font face="Arial" color="#ffffff" size="2">Copyright © 2007 <a href="" target="_blank"></a>. All Rights Reserved.</FONT></TD>
  <TD align=right class=headera2><font class=linksmall><font face="Arial" color="#ffffff" size="2">Email : <A href=""></A> &nbsp;&nbsp;&nbsp; </font></TD>
 </TR>
</TABLE>
</Body>
</BODY>
</HTML>
chrisj is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 02-06-2008, 03:37 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Super Moderator

Posts: 11,495
Location: Blackpool. UK
in the save files function

have this line
Upload.Save(uploadsDirVar)

twice and point the other one to a different directory.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-07-2008, 03:51 PM Re: Uploading to more than one directory?
Super Talker

Posts: 115
Thank you. I'll try it.
chrisj is offline
Reply With Quote
View Public Profile
 
Old 02-08-2008, 03:56 PM Re: Uploading to more than one directory?
Super Talker

Posts: 115
Thank you for these instructions:

"in the save files function

have this line
Upload.Save(uploadsDirVar)

twice and point the other one to a different directory"


I tried this and everything uploaded to the "different directory" only,
instead of one upload to one directory and another upload to the other directory.

This is what I did as per your instructions:

In here I added a different (2nd) destination directory:

Code:
' ****************************************************
  Dim uploadsDirVar
  uploadsDirVar = "C:/Input/"
  uploadsDirVar = "C:/Input2/"
' ****************************************************
And I added this "Upload.Save(uploadsDirVar)" again in the Save files function as shown below:

Code:
function SaveFiles
    Dim Upload, fileName, fileSize, ks, i, fileKey
    Set Upload = New FreeASPUpload
    Upload.setMaxFileSize 0.5, "m"
    Upload.Save(uploadsDirVar)
    Upload.Save(uploadsDirVar)
So, I must have done something incorrect.
Can you tell me what I've done wrong?

Thanks again so much.
chrisj is offline
Reply With Quote
View Public Profile
 
Old 02-08-2008, 04:35 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Super Moderator

Posts: 11,495
Location: Blackpool. UK
Ok

Code:
  Dim uploadsDirVar
  uploadsDirVar = "C:/Input/"
  uploadsDirVar = "C:/Input2/"
What is the value of uploadsDirVar after this operation and where do you think BOTH uploads of the same file will go to?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-08-2008, 04:49 PM Re: Uploading to more than one directory?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
There's a much better way to do this. Upload it to one directory only, destroy the Upload object, and use FileSystemObject to copy the file.

http://www.w3schools.com/asp/met_copyfile.asp
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-08-2008, 06:25 PM Re: Uploading to more than one directory?
Learning Newbie's Avatar
Moderator

Latest Blog Post:
Dick Cheney as a Web Comic
Posts: 4,622
Name: John Alexander
There's a MUCH better way to do this. Y'all won't like me, though.

Use the file upload control that's built into ASP.NET and then use File.Copy(source, destination) to duplicate it anywhere you'd like. No 3rd Party scripts to debug or wonder about whether the API allows for multiple saves. No inefficient network streaming, non-atomic file operations, or any of that.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-08-2008, 06:38 PM Re: Uploading to more than one directory?
Super Talker

Posts: 115
Thanks for your replies.

Your question: "What is the value of uploadsDirVar after this operation"?
I don't know where to find that information for you. Can you tell me where I can find the value?

"where do you think BOTH uploads of the same file will go to?
I uploaded two of the same files, but saw only one in C:/Input2/

Any additional assistance will be appreciated.
chrisj is offline
Reply With Quote
View Public Profile
 
Old 02-08-2008, 06:42 PM Re: Uploading to more than one directory?
Super Talker

Posts: 115
Regarding "Upload it to one directory only, destroy the Upload object, and use FileSystemObject to copy the file", that's beyond my skill level, but if it's a good solution, I'd like to try it also.

The example in the link showed this:

Code:
<%
dim fs
set fs=Server.CreateObject("Scripting.FileSystemObject")
fs.CopyFile "c:\mydocuments\web\*.htm","c:\webpages\"
set fs=nothing
%>
Can you tell me how I could use this in my particular case? I'm not sure I understand what's happening with the example.

Thanks.
chrisj is offline
Reply With Quote
View Public Profile
 
Old 02-08-2008, 07:30 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Super Moderator

Posts: 11,495
Location: Blackpool. UK
Quote:
I don't know where to find that information for you. Can you tell me where I can find the value?
Meanwhile back at "debugging101"
Code:
 Dim uploadsDirVar
  uploadsDirVar = "C:/Input/"
  uploadsDirVar = "C:/Input2/"
response.write uploadsDirVar 
Quote:
I uploaded two of the same files, but saw only one in C:/Input2/
And logic, (very important for programmers) tells you this is because?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-09-2008, 02:34 AM Re: Uploading to more than one directory?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,025
Name: Forrest Croce
Location: Seattle, WA
Quote:
Originally Posted by chrisj View Post
Can you tell me how I could use this in my particular case? I'm not sure I understand what's happening with the example.
<% [Starts a code block]
dim fs [Creates a variable to work with the file system]
set fs=Server.CreateObject("Scripting.FileSystemObject ") [Gives that a variable a value]
fs.CopyFile "c:\mydocuments\web\*.htm","c:\webpages\" [Uses that variable to copy files]
set fs=nothing [Clear the variable]
%> [Ends the code block]

Last edited by ForrestCroce : 02-09-2008 at 02:35 AM.
ForrestCroce is online now
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-11-2008, 11:42 AM Re: Uploading to more than one directory?
Super Talker

Posts: 115
Thanks for all your replies.

Chris Hirst, you are very funny, and very, very helpful. Thanks for your kindness and patience while helping me. I greatly appreciate it.

After adding response.write uploadsDirVar, I see that the value shows on the uploadtester,asp page as this: "C:/Input2/", so logic tells me that this is where both of the same uploaded files are going, and I only see one of those files in "C:/Input2/", and that's because one file is overwriting the other file when it arrives in that directory? possibly?

No files show up in "C:/Input/".

So, I'm not sure why no files are going to C/Input/, and only to C/Input2/.
Your guidance/wisdom/assistance will be greatly appreciated.
chrisj is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 12:35 PM Re: Uploading to more than one directory?
Super Talker

Posts: 115
Thanks for outlining the example.
Could you please tell me what is going on with this line?

fs.CopyFile "c:\mydocuments\web\*.htm","c:\webpages\" [Uses that variable to copy files]

Are you saying that files uploaded to C;\mydocuments\web\*.htm are automatically copied to c:\webpages\?

If so, how does this provide a solution for my original request of "can upload to more than one directory?" where "the first file gets uploaded to directory A, the next upload gets uploaded to Directory B, the next file gets uploaded to directory A again, the next file gets uploaded to directory B again, and so on."?

Thanks again.
chrisj is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 01:23 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Super Moderator

Posts: 11,495
Location: Blackpool. UK
Quote:
and that's because one file is overwriting the other file when it arrives in that directory? possibly?
Absolutely correct.

What you need is TWO distinct values (variables) for your upload destination. One Upload.Save() points to one location, the second points to the other.

Quote:
Are you saying that files uploaded to C;\mydocuments\web\*.htm are automatically copied to c:\webpages\?
Almost. The above snippet copies all .htm files to the destination folder, any other file extension will NOT be affected.

How it helps is that you recode it slightly.

Get the name and path of the uploaded file and copy that one only
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-11-2008, 02:44 PM Re: Uploading to more than one directory?
Experienced Talker

Posts: 33
Name: Jack
Great thread, thanks for replies!! very helpfull
__________________
Xpantivirus
Remove VirusHeat
jacklazara is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 05:03 PM Re: Uploading to more than one directory?
Super Talker

Posts: 115
Thanks for educating me. Greatly, greatly appreciated.

So would this work?

' ************************************************** **
Dim uploadsDirVar
uploadsDirVar = "C:/Input/"
uploadsDirVar2 = "C:/Input2/"
' ************************************************** **
and this?:

function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey
Set Upload = New FreeASPUpload
Upload.setMaxFileSize 0.5, "m"
Upload.Save(uploadsDirVar)
Upload.Save(uploadsDirVar2)

__________________________________________________ ____________

And I understand and appreciate your explanation "The above snippet copies all .htm files to the destination folder, any other file extension will NOT be affected."

But I don't see how that "uploads to more than one directory"? It would put(copy) the same file in two directories, instead of putting a file in A directory and another file in B directory, wouldn't it?

I don't understand "Get the name and path of the uploaded file and copy that one only?" Not sure what you mean by that.

Sincere thanks for any clarification.
chrisj is offline