Replies Back to Article
Can I upload to multiple directories?
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.
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.
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
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 :-)