Can I upload to multiple directories? Support
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
Comments
Good solution but watch out!
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
RE: 3 images to upload
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
You must me logged in to write a comment.