Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



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

Posts: 216
Trades: 0
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
 
 
Register now for full access!
Old 02-06-2008, 04:37 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-07-2008, 04:51 PM Re: Uploading to more than one directory?
Extreme Talker

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

Posts: 216
Trades: 0
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, 05:35 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-08-2008, 05:49 PM Re: Uploading to more than one directory?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 02-08-2008, 07:25 PM Re: Uploading to more than one directory?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-08-2008, 07:38 PM Re: Uploading to more than one directory?
Extreme Talker

Posts: 216
Trades: 0
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, 07:42 PM Re: Uploading to more than one directory?
Extreme Talker

Posts: 216
Trades: 0
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, 08:30 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-09-2008, 03:34 AM Re: Uploading to more than one directory?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
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]
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

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

Posts: 216
Trades: 0
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, 01:35 PM Re: Uploading to more than one directory?
Extreme Talker

Posts: 216
Trades: 0
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, 02:23 PM Re: Uploading to more than one directory?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
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!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-11-2008, 03:44 PM Re: Uploading to more than one directory?
Experienced Talker

Posts: 33
Name: Jack
Trades: 0
Great thread, thanks for replies!! very helpfull
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

jacklazara is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 06:03 PM Re: Uploading to more than one directory?
Extreme Talker

Posts: 216
Trades: 0
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
Reply With Quote
View Public Profile
 
Old 02-11-2008, 07:04 PM Re: Uploading to more than one directory?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
' ************************************************** **
Dim uploadsDirVar, uploadsDirVar2
uploadsDirVar = "C:/Input/"
uploadsDirVar2 = "C:/Input2/"
' ************************************************** **

You missed the one in purple.

Quote:
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?
Adam was showing you how to use the file system from within ASP to make a copy of a a file, or a group of files. If you want the user to upload a file into two places, you can accomplish that by changing how your uploads work or by making a copy of the file that gets uploaded in the 2nd place you need it. Do you really care which one? Probably not, as long as the same file is in both places. But with the knowledge of how to copy a file, you need to change the code slightly so that instead of copying all html files from a folder that probably doesn't exist on your server, it changes to only copy what's been uploaded.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 07:12 PM Re: Uploading to more than one directory?
Extreme Talker

Posts: 216
Trades: 0
Thanks for your reply and explanation. I appreciate it.

I never wanted "the same file in both places".

I explained this in my initial post:

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.

Can the copying code accomplish that?

Thanks again.
chrisj is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 09:18 PM Re: Uploading to more than one directory?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by chrisj View Post
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.
Oh. I think everybody here missed that. Probably explains a lot of the confusion.

No, ignore most of what we all wrote. Keep the "backgrounder info" but dump the implementation details. Everybody was using different ways to suggest how to put 1 file in 2 places.

Sorry to tell you this, but what you want to do is much harder. Don't worry, it won't be super difficult, and we can help you as long as we all put the beer down. But what no one realized is this means your script needs to remember where it put the file last time, and then know to put it in the other folder this time. That probably means logging uploads to a database - which is a good idea anyway.

Are you already using a database in your script? There are other ways to go about it if need be, but that's probably the best one all around.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 02-11-2008, 10:27 PM Re: Uploading to more than one directory?
Extreme Talker

Posts: 216
Trades: 0
I am using MSSQL for another script where users are stored.

Regarding:

' ************************************************** **
Dim uploadsDirVar, uploadsDirVar2
uploadsDirVar = "C:/Input/"
uploadsDirVar2 = "C:/Input2/"
' ************************************************** **

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

When tested, all uploaded files ended up in both Input and Input2 directories.

Any help to alternate the uploads to Input and then Input2, would be appreciated. Thanks.
chrisj is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Uploading to more than one directory?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.66344 seconds with 12 queries