#include-once #Region Includes #include #include #include #include #EndRegion Includes #Region Global Variables Global $sHeader, $sCookie, $sAuthenticityToken, $sTokenId, $sTokenSecret Global $sBoundary = '--' & _GenerateBoundary(30) ;[N][0] = Images Hosting - the host name before ".com" is used to call upload func name: ; Call('_Host' & StringRegExpReplace($aSupported_Hosts[N][0], '\.[^\.]+$', '') & 'Upload', $sImagePath) ;[N][1] = API key/ID Global $aSupported_Hosts[6][2] = _ [ _ ['imgur.com', 'f77d0b8cd41eb62792be0bf303e649df'], _ ['tinypic.com', 'e2aabb8d555322fa'], _ ['bayimg.com', ''], _ ['abload.de', ''], _ ['postimage.org', ''], _ ['imagebam.com', ''] _ ] Global $sSupported_ImageHosts = $aSupported_Hosts[0][0] For $i = 1 To UBound($aSupported_Hosts) - 1 $sSupported_ImageHosts &= '|' & $aSupported_Hosts[$i][0] Next Global Enum $iHost_imgur, $iHost_tinypic, $iHost_bayimg, $iHost_abload, $iHost_postimage, $iHost_imagebam Global $sUserAgent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)' Global $hUpldPrgrs_Callback_Func = '' #EndRegion Global Variables Func _FileGetType($sFilePath) If Not FileExists($sFilePath) Then Return SetError(-1) If FileGetSize($sFilePath) = 0 Then Return SetError(2, 0, 0) Local $sExt = StringUpper(_GetExtByFullPath($sFilePath)) Local $hFile, $Binary $hFile = FileOpen($sFilePath, 16) If $hFile = -1 Then Return SetError(3, 0, 0) $Binary = FileRead($hFile) FileClose($hFile) Local $sString = StringTrimLeft($Binary, 2) Local $sStringLeft = StringReplace(StringTrimLeft(StringLeft($Binary, 14), 2), '00', '') ; get 7 bit header part. Local $sStringLeft12 = StringLeft($sStringLeft, 12) Local $sStringLeft8 = StringLeft($sStringLeft, 8) Local $sStringLeft6 = StringLeft($sStringLeft, 6) Local $sStringLeft4 = StringLeft($sStringLeft, 4) Local $aOut[2], $aMOPwppSubHeader[5] = [5, '006E1EF0', '0F00E803', 'A0461DF0', 'FDFFFFFF'] ; 60211BF0 403D1AF0 807A1FF0 Local $SubHeader, $iIndex Select #Region ------ Picture Filetype ------------------------------ Case $sStringLeft12 = '474946383961' ; GIF 89A Bitmap GIF Graphics interchange format file $aOut[0] = 'GIF 89A Bitmap' $aOut[1] = 'GIF' Case $sStringLeft12 = '474946383761' ; GIF 87A Bitmap GIF Graphics interchange format file $aOut[0] = 'GIF 87A Bitmap' $aOut[1] = 'GIF' Case $sStringLeft8 = 'FFD8FFE0' ; JFIF, JPE, JPEG, JPG JPEG/JFIF graphics file $aOut[0] = 'JPEG/JFIF graphics file' $aOut[1] = 'JPG' Case $sStringLeft8 = 'FFD8FFE1' ; JPG Standard JPEG/Exif $aOut[0] = 'Standard JPEG/Exif' $aOut[1] = 'JPG' Case $sStringLeft8 = 'FFD8FFE2' ; JPG Canon EOS 1D JPEG file $aOut[0] = 'Canon EOS 1D JPEG file' $aOut[1] = 'JPG' Case $sStringLeft8 = 'FFD8FFE3' ; JPG Samsung D500 JPEG file $aOut[0] = 'Samsung D500 JPEG file' $aOut[1] = 'JPG' Case $sStringLeft8 = 'FFD8FFE8' ; JPG Still Picture Interchange File Format (SPIFF) $aOut[0] = 'Still Picture Interchange File Format (SPIFF)' $aOut[1] = 'JPG' Case $sStringLeft8 = 'FFD8FFDB' ; JPG Samsung D807 JPEG file $aOut[0] = 'Samsung D807 JPEG file' $aOut[1] = 'JPG' Case $sStringLeft4 = 'FFD8' ; JPG $aOut[0] = 'JPEG file' $aOut[1] = 'JPG' Case $sStringLeft4 = '424D' ; BMP, DIB Windows (or device-independent) bitmap image $aOut[0] = 'Windows Bitmap BMP' $aOut[1] = 'BMP' Case $sStringLeft8 = '89504E47' ; PNG $aOut[0] = 'Portable Network Graphics PNG' $aOut[1] = 'PNG' Case $sStringLeft6 = '492049' ; TIF, TIFF Tagged Image File Format file $aOut[0] = 'Tagged Image File Format file' $aOut[1] = 'TIFF' Case $sStringLeft8 = '49492A00' ; TIF, TIFF Tagged Image File Format file (little endian, i.e., LSB first in the byte; Intel) $aOut[0] = 'Tagged Image File Format file little endian' $aOut[1] = 'TIFF' Case $sStringLeft6 = '4D4D2A' ; TIF, TIFF Tagged Image File Format file (big endian, i.e., LSB last in the byte; Motorola) $aOut[0] = 'Tagged Image File Format file big endian' $aOut[1] = 'TIFF' Case $sStringLeft6 = '4D4D2B' ; TIF, TIFF BigTIFF files; Tagged Image File Format files >4 GB $aOut[0] = 'BigTIFF files' $aOut[1] = 'TIFF' #EndRegion --- Picture Filetype ------------------------------ #Region ------ Document Filetype ------------------------------ Case $sStringLeft8 = '25504446' ; PDF, FDF Adobe Portable Document Format and Forms Document file $aOut[0] = 'Adobe Portable Document Format' $aOut[1] = 'PDF' Case $sStringLeft8 = 'D0CF11E0' $SubHeader = StringMid($sString, 1025, 8) ; offset 512 If $SubHeader = 'ECA5C100' Then $aOut[0] = 'Microsoft Word document' $aOut[1] = 'DOC' Else $iIndex = _ArraySearch($aMOPwppSubHeader, $SubHeader, 1, 0, 0, 0) If $iIndex > 0 Or StringInStr($sString, StringTrimLeft(Binary('PowerPoint'), 2)) Then $aOut[0] = 'Microsoft PowerPoint document' If $sExt = 'PPS' Then $aOut[1] = 'PPS' Else $aOut[1] = 'PPT' EndIf EndIf EndIf Case $sStringLeft8 = '504B0304' ; odp, odt, docx, pptx, ppsx et zip 504B0304 If StringInStr($sString, StringTrimLeft(Binary('opendocument.presentationPK'), 2)) Then $aOut[0] = 'OpenDocument Presentation' $aOut[1] = 'ODP' ContinueCase EndIf If StringInStr($sString, StringTrimLeft(Binary('opendocument.textPK'), 2)) Then $aOut[0] = 'OpenDocument Text document' $aOut[1] = 'ODT' ContinueCase EndIf If StringInStr($sString, StringTrimLeft(Binary('word/_rels/document.xml.rels'), 2)) Then $aOut[0] = 'Word Microsoft Office Open XML Format document' $aOut[1] = 'DOCX' ContinueCase EndIf If StringInStr($sString, StringTrimLeft(Binary('ppt/_rels/presentation.xml.rel'), 2)) Then $aOut[0] = 'PowerPoint Microsoft Office Open XML Format document' If $sExt = 'PPSX' Then $aOut[1] = 'PPSX' Else $aOut[1] = 'PPTX' EndIf ContinueCase EndIf #EndRegion --- Document Filetype ------------------------------ EndSelect If $aOut[1] = 'GIF' Then StringReplace($sString, '0021F904', '0021F904') If @extended > 1 Then $aOut[0] = 'Animated ' & $aOut[0] EndIf Return $aOut EndFunc ;==> _FileGetType () Func _PicReadData($sPicPath) If Not FileExists($sPicPath) Then Return SetError(-1) Local $hFile = FileOpen($sPicPath) If $hFile = -1 Then Return SetError(1) Local $sData = FileRead($hFile) If @error Then Return SetError(2) FileClose($hFile) Return $sData EndFunc ;==> _PicReadData () Func _PicGetContentType($sPicPath) If Not FileExists($sPicPath) Then Return SetError(-1) Local $sExt = _GetExtByFullPath($sPicPath) If @error Or $sExt = '' Then Return SetError(1) Local $sContentType Switch $sExt Case 'jpg', 'jpe', 'jpeg' $sContentType = 'Content-Type: image/jpeg' ; ie 'Content-Type: image/pjpeg' Case 'gif' $sContentType = 'Content-Type: image/gif' Case 'bmp' $sContentType = 'Content-Type: image/bmp' Case 'png' $sContentType = 'Content-Type: image/png' ; ie Content-Type: image/x-png Case 'tif', 'tiff' $sContentType = 'Content-Type: image/tiff' Case Else Return SetError(2) EndSwitch Return $sContentType EndFunc ;==> _PicGetContentType () Func _PicUploadProgress($hRequest, $sPicPath, $sDataToSend) If Not FileExists($sPicPath) Then Return SetError(-1) Local $sDatas = StringToBinary($sDataToSend) Local $iNumberOfBytesToSend = 2048 ; 1024; 2048; 8192 Local $Bin, $iPercent, $iStart = 1, $iExtended = 0 While 1 $Bin = BinaryMid($sDatas, $iStart, $iNumberOfBytesToSend) If BinaryLen($Bin) = 0 Then Return _WinHTTPWriteData($hRequest, $Bin, 1) If Not @error Then $iExtended += @extended $iPercent = Round(($iExtended) / (StringLen($sDataToSend)) * 100, 2) If $iPercent > 100 Then $iPercent = 100 If IsFunc($hUpldPrgrs_Callback_Func) Then $hUpldPrgrs_Callback_Func($iPercent) EndIf $iStart += $iNumberOfBytesToSend Else $Bin = 0 Return SetError(1) EndIf WEnd EndFunc Func _GenerateBoundary($iLen) Local $sString = '' Do Switch Random(1, 3, 1) Case 1 $sString &= Chr(Random(48, 57, 1)) ; 0 to 9 Case 2 $sString &= Chr(Random(65, 90, 1)) ; A to Z Case 3 $sString &= Chr(Random(97, 122, 1)) ; a to z EndSwitch Until StringLen($sString) = $iLen Return $sString EndFunc ;==> _GenerateBoundary () Func _GenerateRandomName($sDir) Local $sTempName, $sTempPath Do $sTempName = '~' While StringLen($sTempName) < 8 $sTempName = $sTempName & Chr(Round(Random(97, 122), 0)) WEnd $sTempPath = $sDir & '\' & $sTempName Until Not FileExists($sTempPath) Return $sTempName EndFunc ;==> _GenerateRandomName () Func _GetExtByFullPath($sFullPath) Local $aFileName = StringSplit($sFullPath, '.') If Not @error Then Return $aFileName[$aFileName[0]] Return SetError(1) EndFunc ;==> _GetExtByFullPath () Func _GetFullNameByFullPath($sFullPath) Local $aFileName = StringSplit($sFullPath, '\') If Not @error Then Return $aFileName[$aFileName[0]] Return SetError(1) EndFunc ;==> _GetFullNameByFullPath () Func _GetNameByFullPath($sFullPath) Local $aFileName = StringSplit($sFullPath, '\') If Not @error Then Return StringLeft($aFileName[$aFileName[0]], StringInStr($aFileName[$aFileName[0]], '.', 0, -1) - 1) EndFunc ;==> _GetNameByFullPath () Func _HostAbloadExtractLinks($HtmlData) Local $sUrl Local $aLinks = StringRegExp($HtmlData, '(?s)(?i)value="(.*?)"', 3) If Not @error Then _ArrayDelete($aLinks, 0) _ArrayDelete($aLinks, 0) $sUrl = _StringBetween($aLinks[1], '[img]', '[/img]') If Not @error Then $aLinks[1] = $sUrl[0] _ArrayDelete($aLinks, 3) ReDim $aLinks[4] If $aLinks[UBound($aLinks) - 1] <> '' Then Return $aLinks Else Return SetError(3) EndIf Else Return SetError(2) EndIf Else Return SetError(1) EndIf EndFunc ;==> _HostAbloadExtractLinks () Func _HostAbloadSetDataToSend($sPicPath) If Not FileExists($sPicPath) Then Return SetError(-1) Local $sData = _PicReadData($sPicPath) If @error Then Return SetError(1) Local $sImageName = _GetFullNameByFullPath($sPicPath) If @error Or $sImageName = '' Then Return SetError(2) Local $sContentType = _PicGetContentType($sPicPath) If @error Then Return SetError(3) Return SetError(0, '', $sBoundary & @CRLF & _ 'Content-Disposition: form-data; name="img0"; filename="' & $sImageName & '"' & @CRLF & $sContentType & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF & _ 'Content-Disposition: form-data; name="resize"' & @CRLF & @CRLF & 'none' & @CRLF & $sBoundary & @CRLF & _ 'Content-Disposition: form-data; name="delete"' & @CRLF & @CRLF & 'never' & @CRLF & $sBoundary & '--') EndFunc ;==> _HostAbloadSetDataToSend () Func _HostAbloadUpload($sPicPath) Local $hOpen, $hConnect, $hRequest, $sHost, $sDataToSend, $sReceivedData, $iError, $sResponse, $sPostData, $sContentType, $aName, $aValue, $aData $sHost = 'abload.de' $hOpen = _WinHttpOpen($sUserAgent) If @error Then SetError(1) Else $hConnect = _WinHttpConnect($hOpen, $sHost) If @error Then SetError(2) Else $hRequest = _WinHttpOpenRequest($hConnect, 'POST', '/upload.php', 'HTTP/1.1') If @error Then SetError(3) Else _WinHttpSetTimeouts($hRequest, 10000, 60000, 90000, 90000) $sDataToSend = _HostAbloadSetDataToSend($sPicPath) _WinHttpAddRequestHeaders($hRequest, 'Accept:application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/x-silverlight, */*') _WinHttpAddRequestHeaders($hRequest, 'Referer: http://abload.de/') _WinHttpAddRequestHeaders($hRequest, 'Accept-Encoding:gzip, deflate') _WinHttpAddRequestHeaders($hRequest, 'Connection:Keep-Alive') _WinHttpAddRequestHeaders($hRequest, 'Cache-Control:no-cache') $sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft($sBoundary, 2) _WinHttpSendRequest($hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen($sDataToSend)) If @error Then SetError(4) Else _PicUploadProgress($hRequest, $sPicPath, $sDataToSend) If Not @error Then $hTimerInit = TimerInit() _WinHttpReceiveResponse($hRequest) If @error Then SetError(5) Else If _WinHttpQueryDataAvailable($hRequest) Then $sReceivedData = '' While 1 $sReceivedData &= _WinHttpReadData($hRequest) If Not @extended Then ExitLoop ;~ WEnd If StringInStr($sReceivedData, 'error') Then SetError(6) $aName = _StringBetween($sReceivedData, 'name="', '"') If Not @error Then $aValue = _StringBetween($sReceivedData, 'value="', '"') If Not @error Then $aData = _StringBetween($sReceivedData, 'display:none;">', '