Replies Back to Article

Can I upload to multiple directories?

Good solution but watch out!
October 29, 2004 by Charles Beaudry

Tjis solved one of the problems I ran into during development of a CMS. If you are using the script for multiple areas and multiple extensions, I suggest you create a second file and manually change the include statement at the top.

In my case, I needed to upload .css and images files to specific folders simultaneously. These modifications did the trick. However, in another part of my CMS, the images were being uploaded to a different folder. As a result, I had to create two separate "incPureUpload.asp" files, one for the normal routine, and one for the multiple file upload routine. Then I manually edited the include path in the page where the separate forms resided to point to the right routine.

Now everything works great.

3 images to upload
July 28, 2005 by Stephen Davidson
I have 3 images to upload, a low res JPG, a medium res JPG and and high res ZIP file, could the above method be adapted to upload these three files to three diferent folders? Many thanks... Stephen
RE: 3 images to upload
July 29, 2005 by Jim Castanes

I would think that you could, as long as you keep a common standard for all your file naming.

In my example I was looking for a "zip" file extension in the "GP_CurFileName" variable. I would suggest naming your low res files something like “filenameLo.jpg“ and your high res files something like “filenameHi.jpg”.(Of course you can use whatever naming you choose)

Then to set the variable for the path do the following:

'Get the path
GP_CurFileName = UploadRequest.Item (GP_curKey).Item("FileName")
Dim varExt
Dim varPath
varExt =Right(GP_CurFileName,6)
If varExt = "Lo.jpg" Then
varPath = "LowRes"
Elseif varExt = "Hi.jpg" Then
varPath = "HiRes"
Else
varPath = "Zip"
End If

This will look for your hi and low res jpg files and anything else(which will be your zip files) will go into your zip folder.

RE: RE: 3 images to upload
July 29, 2005 by Stephen Davidson
Thanks for the reply Jim, i have it working a treat now, and it has got me thinking. Would it not be easier to use the If Then Else dependant on the file field names? I mean on my form I have the three upload fields named accordingly, surely the upload component can pick up on this which would mean that we don’t need to check the charters in the filename etc and it would allow for all kinds of permutations.. Just a thought! And thanks again. Stephen
RE: RE: RE: 3 images to upload
July 29, 2005 by Stephen Davidson
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
RE: RE: RE: RE: 3 images to upload
July 29, 2005 by Stephen Davidson
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: RE: RE: 3 images to upload
July 29, 2005 by Jim Castanes

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

Upload to 3 folders
July 29, 2005 by Jim Castanes

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 :-)