'Option Explicit
Private Declare Function BmpToJpeg Lib "Bmp2Jpeg.dll" ( _
ByVal BmpFilename As String, _
ByVal JpegFilename As String, _
ByVal CompressQuality As Integer) As Integer
'ftp functions via vbforums.com, Joacim Andersson
Private Declare Function FtpGetFile Lib "wininet.dll" _
Alias "FtpGetFileA" ( _
ByVal hFtpSession As Long, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" _
Alias "FtpPutFileA" ( _
ByVal hFtpSession As Long, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Private Declare Function InternetOpen Lib "wininet.dll" _
Alias "InternetOpenA" ( _
ByVal sAgent As String, _
ByVal nAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyByPass As String, _
ByVal nFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" _
Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUserName As String, _
ByVal sPassword As String, _
ByVal nService As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Private Declare Function FtpCreateDirectory _
Lib "wininet.dll" Alias "FtpCreateDirectoryA" ( _
ByVal hFtpSession As Long, _
ByVal lpszDirectoryName As String) As Boolean
Private Declare Function FtpSetCurrentDirectory _
Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" ( _
ByVal hFtpSession As Long, _
ByVal lpszDirectoryName As String) As Boolean
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
ByVal hInet As Long) As Integer
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_SERVICE_GOPHER = 2
Private Const INTERNET_SERVICE_HTTP = 3
Public Sub resizePic()
Dim filename, picpath, reverse As String
Dim start, i As Integer
Picture1.Picture = LoadPicture()
Picture2.Picture = LoadPicture()
reverse = ""
For i = 1 To Len(frmSwitchboard.rsProperty.Fields("pr_pic").Value)
reverse = reverse & Mid(frmSwitchboard.rsProperty.Fields("pr_pic").Value, Len(frmSwitchboard.rsProperty.Fields("pr_pic").Value) - i + 1, 1)
Next
start = InStr(1, reverse, "\")
'picpath = Mid(rsProperty.Fields("pr_pic"), 1, Len(rsProperty.Fields("pr_pic")) - start)
filename = Mid(frmSwitchboard.rsProperty.Fields("pr_pic"), Len(frmSwitchboard.rsProperty.Fields("pr_pic")) - start + 2, start - 5)
'filename = Left(dlg.filename, Len(dlg.filename) - 4)
Picture1.Picture = LoadPicture(frmSwitchboard.rsProperty.Fields("pr_pic"))
'Resizing
Picture2.AutoRedraw = True
'Picture2.Width = 400
'Picture2.Height = 300
Picture2.PaintPicture Picture1.Picture, _
Picture2.ScaleLeft, Picture2.ScaleTop, _
Picture2.ScaleWidth, Picture2.ScaleHeight, _
Picture1.ScaleLeft, Picture1.ScaleTop
Picture2.Picture = Picture2.Image
'Saving the file as Bitmap
SavePicture Picture2.Picture, "C:\" & filename & ".bmp"
'For saving into jpg format you must have
'the Bmp2Jpeg.dll file in your windows folder
'Change the bitmap file to the jpg file with the Bmp2Jpg.dll
'60 is the Compress Quality
BmpToJpeg "C:\" & filename & ".bmp", "C:\" & filename & ".jpg", 60
'Deleting the bitmap file
Kill "C:\" & filename & ".bmp"
uploadPic frmSwitchboard.rsProperty.Fields("pr_code").Value, "C:\", filename & ".jpg"
Kill "C:\" & filename & ".jpg"
End Sub
Public Sub uploadPic(dirName As String, filePath As String, file As String)
'dirName = name of target folder on server
'filePath is e.g. "C:\"
'file full name of the file, e.g. "picture.jpg"
'Dim hINetSession As Variant
'Dim hsession As Variant
retry:
hINetSession = InternetOpen("testftp", 0, vbNullString, vbNullString, 0)
hsession = InternetConnect(hINetSession, "127.0.0.1", "21", "test", "test", INTERNET_SERVICE_FTP, 0, 0)
If FtpSetCurrentDirectory(hsession, dirName) = False Then
FtpCreateDirectory hsession, dirName
End If
FtpSetCurrentDirectory hsession, dirName
If FtpPutFile(hsession, filePath & file, file, 1, 0) = False Then
If MsgBox("Error occurred. Code: " & Err.LastDllError & vbCrLf & "Retry?", vbYesNo + vbQuestion) = vbYes Then
GoTo retry:
Else
MsgBox ("Upload failed.")
Exit Sub
End If
Else
MsgBox "upload success"
End If
Call InternetCloseHandle(hsession)
Call InternetCloseHandle(hINetSession)
End Sub