|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
FTP files of a certain type!!
Hi folks. I have the following function which saves uploaded files (where path is the path to upload to):
Public Sub Save(path) Dim streamFile, fileItem if Right(path, 1) <> "\" then path = path & "\" if not uploadedYet then Upload For Each fileItem In UploadedFiles.Items if fileItem.Length > 30000 then else Set streamFile = Server.CreateObject("ADODB.Stream") streamFile.Type = 1 streamFile.Open StreamRequest.Position=fileItem.Start StreamRequest.CopyTo streamFile, fileItem.Length streamFile.SaveToFile path & fileItem.FileName, 2 streamFile.close Set streamFile = Nothing fileItem.Path = path & fileItem.FileName end if Next End Sub The trouble is, I want users only to be able to upload files of a certain type, eg jpg's. I tried adding the following code..... if (fileItem.FileName.GetExtensionName(path & fileItem.FileName) = "jpg") then but I get the error:Object required: 'fileItem.FileNam' I know why the error occurs, but don't know how to solve the problem!! Any help would be much appreciated!
__________________
Captain Planet. |
|
#2
|
|||
|
|||
|
Apparently you are not inserting the check line of code in the Save sub.
__________________
====== Doug G ====== "Hide, hide witch! The good folk come to burn thee. Their keen enjoyment hid behind their gothic mask of duty." -Mark Clifton |
|
#3
|
||||
|
||||
|
Cheers Doug (tho not sure what you meant??)
For anyone who has this problem in the future, I solved it. Here's the code. Code:
Public Sub Save(path)
Dim streamFile,originName,fileItem, fileType, sSplit
if Right(path, 1) <> "\" then path = path & "\"
if not uploadedYet then Upload
For Each fileItem In UploadedFiles.Items
if fileItem.Length > 30000 then
else
originName = fileItem.FileName
'filter off the path to get the actual file name ("\")
If Len(originName) > 0 Then
sSplit = split(originName, "\")
fileType = sSplit(ubound(sSplit))
Set sSplit = Nothing
If Instr(fileType, ".") = 0 Then 'If there is no file extension
fileType = ".doc"
Else
'filter off the file name to get the file type (".")
sSplit = split(fileType, ".")
fileType = sSplit(ubound(sSplit))
fileType = "." & LCase(fileType)
Set sSplit = Nothing
End If
If filetype = ".doc" Or filetype = ".xls" Or filetype = ".pdf" Or filetype = ".rtf" Or filetype = ".htm" Or filetype = ".html" Or filetype = ".txt" Or filetype = ".gif" Or filetype = ".jpg" Then
'Response.Write filetype
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = 1
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & fileItem.FileName, 2
streamFile.close
Set streamFile = Nothing
fileItem.Path = path & fileItem.FileName
end if
end if
end if
Next
End Sub
|
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > FTP files of a certain type!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|