Back to Top
The nuts and bolts for
Creative web development

Can I upload to multiple directories?

Question:


Is it possible to submit two files (i.e. one image and one zip) and have them go into different directories?

Answer:


I was able to do this by adding the following lines to the “incPureUpload.asp” file after the “Get the path” on line 149. I’m putting zip files in one folder and images in the other by setting the varExt with the last 3 characters of the file name (the extension) and using it to set my path variable varPath with “If” statements.

'Get the path
GP_CurFileName = UploadRequest.Item (GP_curKey).Item("FileName")
Dim varExt
Dim varPath
varExt =Right(GP_CurFileName,3)
If varExt = "zip" Then
varPath = "Maps"
Else
varPath = "Pics"
End If

*And added (& varPath & “\”) to lines 162 and 169 (new line numbers after adding above code)

if InStr(UploadDirectory,"\") > 0 then
GP_curPath = UploadDirectory
if Mid(GP_curPath,Len(GP_curPath),1) <> "\" then
GP_curPath = GP_curPath & "\" & varPath & "\"    <<Added Code here
end if
GP_FullPath = GP_curPath
else
GP_curPath = Request.ServerVariables("PATH_INFO")
GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) & UploadDirectory)
if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then
GP_curPath = GP_curPath & "/" & varPath & "/"     <<Added Code here
end if
GP_FullPath = Trim(Server.mappath(GP_curPath))
end if

You can get more creative with the “If Than” statements to direct multiple file types. The key is using the “GP_CurFileName” variable to set your criteria and that it is on the correct line so that the form will loop through each file name. I’m using the Right(GP_CurFileName,3) so that I can sort by file extension, but you can use any string manipulation that you prefer, such as Left( , ), InStr( , ), InStrRev( , ).

Hope this helps.
JimC

Share this Article

Comments

Upload to 3 folders

Stephen, How about this?

This will change the upload path as it goes through each file to upload. Doesn’t matter what type of file.

Right after “’Get the path (line 245 in my incPureUpload.asp file) add the following.


   'Get the path
   GP_CurFileName = UploadRequest.Item (GP_curKey).Item("FileName")
   Dim varTextField
   Dim varPath
   varTextField = varTextField  + 1
   If varTextField = 1 Then
   varPath = "Folder1"
   ElseIf varTextField = 2 Then
   varPath = "Folder2"
   Else
   varPath = "Folder3"
   End If

Here is the rest of the original code that follows. You now need to add the "varPath" variable in two places (Highlighted below, lines 261 and 283 in my incPureUpload.asp file).

   if InStr(UploadDirectory,"\") > 0 then
    GP_curPath = UploadDirectory
    if Mid(GP_curPath,Len(GP_curPath),1) <> "\" then
     GP_curPath = GP_curPath & "\" & varPath & "\"
    end if        
    GP_FullPath = GP_curPath
   else
    if Left(UploadDirectory,1) = "/" then
     GP_curPath = UploadDirectory
    else
     GP_curPath = Request.ServerVariables("PATH_INFO")
     GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) & UploadDirectory)
     while InStr(GP_curPath, "/./") > 0
      pos = InStr(GP_curPath, "/./")
      GP_curPath = Trim(Mid(GP_curPath,1,pos) & Mid(GP_curPath,pos+3))
     wend
     while InStr(GP_curPath, "/../") > 0
      pos = InStr(GP_curPath, "/../")
      if pos > 1 then
       GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath, "/", pos-1)) & Mid(GP_curPath,pos+4))
      else
       GP_curPath = Trim(Mid(GP_curPath,1,pos) & Mid(GP_curPath,pos+4))
      end if
     wend
     if Mid(GP_curPath,Len(GP_curPath),1)  <> "/" then
      GP_curPath = GP_curPath & "/" & varPath & "/"
     end if
    end if
    GP_FullPath = Trim(Server.mappath(GP_curPath))    
   end if
   if GP_valueLen = 0 then
    Response.Write "<strong>An error has occurred while saving the uploaded file!</strong><br/><br/>"
    Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "<br/>"
    Response.Write "The file does not exists or is empty.<br/>"
    Response.Write "Please correct and <a href=""javascript:history.back(1)"">try again</a>"
    response.End

Hope it works :-)

RE: RE: RE: RE: RE: 3 images to upload

I’m not really sure Stephen. I originally posted this in Dec. 2002 and I haven’t looked at the code since then. I’ll have to play around with it to see how we can redirect the file without it using the file name structure to determine the path. I’m sure it can be done.

When I did this I was only sorting out the zip files, so it was easier. I also wanted to do it without editing too much of the original code (to reduce the possibilities of errors).

I’ll do like I did back then, bang my head on the desk 32 times and read the stars in my eyes for an answer ;-). If that works, I’ll post some ideas for you. Jim

RE: RE: RE: RE: 3 images to upload

I wish i coudl edit my posts! Ok to ge the SIP working you need change SIP code by adding the following pau_thePath = "TheDirectoryWithImageToBeResized" I used pau_thePath = "ImageLibrary/LowRes" Which works well as the medium res folder is untouched... Hope this helps. Stephen

RE: RE: RE: 3 images to upload

I've also noticed that the SIP stops working once you use this method...looking at ways round this and i'll post if i come up with anything. Cheers, Stephen
See all 8 Comments