Jump to content

upload an Image to Imageshack.us


Recommended Posts

Hi,

a long time ago i used a script which i found in the internet to upload pictures to imageshack.us, but now it doesn't work anymore. I really don't have any knowledge about TCP and so on, so can someone please help me and 'repair' the script for me?

Script:

;~ =================> Imageshack Uploader
Func _UploadTo_Imageshack($sFile, $sFlag = 0, $iRet_Type = 0)
    $sLocalFile = $sFile ;Local file
    $sHost = 'http://imageshack.us' ;Upload page addresss
    $sFormAction = '/upload_api.php' ;Upload form action ("form action=...upload.php)"
    $sFormName = 'fileupload' ;Upload form name ("input name=uploadfile")
    $sResponse = _TCPFileUpload($sLocalFile, $sHost, $sFormAction, $sFormName)
    Local $aRet[4] = _
        [ _
            StringRegExpReplace($sResponse, '(?is).*<(image_link)>(.*?)</1>.*', '2'), _
            StringRegExpReplace($sResponse, '(?is).*<(image_html)>(.*?)</1>.*', '2'), _
            StringRegExpReplace($sResponse, '(?is).*<(image_bb)>(.*?)</1>.*', '2'), _
            StringRegExpReplace($sResponse, '(?is).*<(image_bb2)>(.*?)</1>.*', '2') _
        ]
If $sFlag = 1 Then FileDelete($sFile)
Return $aRet[$iRet_Type]
EndFunc
Func _TCPFileUpload($sLocalFile, $sHost, $sFormAction, $sFormName)
    Local $sFileRead, $sFileType, $sBoundary, $sData, $iDataSize, $sHeader, $sCommand, $iSocket, $sRecv
    $sHost = StringRegExpReplace($sHost, '(?i)^https?://', '')
    $sFileRead = FileRead($sLocalFile)
    $sFileType = StringRegExpReplace($sLocalFile, '^.*.', '')
    If $sFileType = 'jpg' Then $sFileType = 'jpeg'
    $sBoundary = StringFormat('----------------%s%s%smzF', @MIN, @HOUR, @SEC)
    $sData = '--' & $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="' & $sFormName & '"; filename="' & StringRegExpReplace($sLocalFile, '^.*', '') & '"' & @CRLF & _
        'Content-Type: image/' & $sFileType & @CRLF & @CRLF & _
        $sFileRead & @CRLF & '--' & $sBoundary & '--' & @CRLF
    $iDataSize = StringLen($sData)
    $sHeader = 'POST ' & $sFormAction & ' HTTP/1.1' & @CRLF & _
                'Host: ' & $sHost & @CRLF & _
                'Connection: close' & @CRLF & _
                'Content-Type: multipart/form-data; boundary=' & $sBoundary & @CRLF & _
                'Content-Length: ' & $iDataSize & @CRLF & @CRLF
    $sCommand = $sHeader & $sData
    TCPStartup()
    $iSocket = TCPConnect(TCPNameToIP($sHost), 80)
    TCPSend($iSocket, $sCommand)
    While 1
        $sRecv &= TCPRecv($iSocket, 20000)
        If StringLen($sRecv) <> 0 Then ExitLoop
        Sleep(50)
    WEnd
    TCPShutdown()
    Return $sRecv
EndFunc

The error I get:

HTTP/1.1 200 OK

Server: nginx/1.0.4

Date: Tue, 01 May 2012 14:12:49 GMT

Content-Type: text/html

Transfer-Encoding: chunked

Connection: close

X-Powered-By: PHP/5.2.9

8c

<links>

<error id="auth_error">You must provide a valid auth token or dev key. see http://code.google.com/p/imageshackapi/</error>

</links>

0

Edited by SYY999
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...