Can I upload to multiple directories?

by Jim Castanes (December 31, 2002)

Question:


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

User Rating (3 votes)
8 reviews available | Read all reviews » | Support forum »

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

User Reviews

Total of 8 reviews
Upload to 3 folders
Written by Jim Castanes on July 29, 2005

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 ...

RE: RE: RE: RE: RE: 3 images to upload
Written by Jim Castanes on July 29, 2005

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 ...

RE: RE: RE: RE: 3 images to upload
Written by Stephen Davidson on July 29, 2005

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 ...

RE: RE: RE: 3 images to upload
Written by Stephen Davidson on July 29, 2005

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: 3 images to upload
Written by Stephen Davidson on July 29, 2005

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 ...

RE: 3 images to upload
Written by Jim Castanes on July 29, 2005

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 ...

3 images to upload
Written by Stephen Davidson on July 28, 2005

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

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

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 ...

Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency