Hi,
ich habe mal ne weile gegooglet und habe mir da was zusammengefummelt aber leider Funzt das nicht ![]()
Ich bekommen keine ersichtlichen errors. Aber die Datei wird nicht Hochgeladen.
Hier mein Scipt
Spoiler anzeigen
#include "WinHTTP.au3"
#include <Array.au3>
Global $MIMETypes[8][2] = [ _
["bmp", "image/bmp"], _
["gif", "image/gif"], _
["jpe", "image/jpeg"], _
["jpeg", "image/jpeg"], _
["jpg", "image/jpeg"], _
["png", "image/png"], _
["tif", "image/tiff"], _
["tiff", "image/tiff"]]
_ArraySort($MIMETypes, 0, 0, 0, 2)
dim $form_files[1][2] = [["fileupload","Avatar.jpg"]]
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]post_multipart("http://localhost/submit.php","",0,$form_files)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]Func post_multipart($host, $selector, $fields, $files)
;~ """
;~ Post fields and files to an http host as multipart/form-data.
;~ fields is a sequence of (name, value) elements for regular form fields.
;~ files is a sequence of (name, filename, value) elements for data to be uploaded as files
;~ Return the server's response page.
;~ """
Local $Return = encode_multipart_formdata($fields, $files)
Local $content_type = 'Content-Type: ' & $Return[0] & @CRLF
;~ $body = $Return[1]
Local $URL = _WinHttpCrackUrl($host)
_ArrayDisplay($Return)
Local $hSession = _WinHttpOpen()
Local $hConnection = _WinHTTPConnect($hSession,$URL[2],$URL[3])
Local $hRequest = _WinHttpOpenRequest($hConnection,"POST",$URL[6]&$URL[7],"HTTP/1.1","http://"&$URL[2])
_WinHttpSendRequest($hRequest,$content_type,$WINHTTP_NO_REQUEST_DATA,StringLen($Return[1]))
_WinHTTPWriteDataBin($hRequest,StringToBinary($Return[1]))
_WinHttpReceiveResponse($hRequest)
Local $Return[2]
If _WinHttpQueryDataAvailable($hRequest) Then
Local $temp
While 1
$temp = _WinHttpReadData($hRequest)
If $temp = "" Then ExitLoop
$Return[1] &=$temp
WEnd
$temp =""
; Does not work since @error is 0, when no more data is available
;~ Do
;~ $Return[1] &= _WinHttpReadData($hRequest)
;~ Until @error <> 0
EndIf
$Return[0] = _WinHttpQueryHeaders($hRequest)
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnection)
_WinHttpCloseHandle($hSession)
Return $Return
EndFunc ;==>post_multipart
; Prog@ndy
Func encode_multipart_formdata($fields, $files)
;~ """
;~ fields is a sequence of (name, value) elements for regular form fields.
;~ files is a sequence of (name, filename, value) elements for data to be uploaded as files
;~ Return (content_type, body) ready for httplib.HTTP instance
;~ """
Local Const $BOUNDARY = getBoundary()
;~ CRLF = '\r\n'
$L = ""
For $i = 0 To UBound($fields) - 1
$L &= ('--' & $BOUNDARY) & @CRLF
$L &= ('Content-Disposition: form-data; name="' & $fields[$i][0] & '"') & @CRLF
$L &= @CRLF
$L &= $fields[$i][1] & @CRLF
Next
For $i = 0 To UBound($files) - 1
$L &= ('--' & $BOUNDARY) & @CRLF
$L &= ('Content-Disposition: form-data; name="' & $files[$i][0] & '"; filename="' & $files[$i][1] & '"') & @CRLF
$content_type = get_content_type($files[$i][1])
$L &= ('Content-Type: ' & $content_type) & @CRLF
$L &= @CRLF
;~ If StringLeft($content_type, 5) <> "text/" Then
;~ $f = FileOpen($files[$i][1], 16)
;~ $L &= BinaryToString(FileRead($f)) & @CRLF
;~ FileClose($f)
;~ Else
$L &= FileRead($files[$i][1]) & @CRLF
;~ EndIf
Next
$L &= ('--' & $BOUNDARY & '--') & @CRLF
$L &= @CRLF
$content_type = 'multipart/form-data; boundary="' & $BOUNDARY & '"'
Local $Return[2] = [$content_type, $L]
;~ return content_type, body
Return $Return
EndFunc ;==>encode_multipart_formdata
; Prog@ndy
Func get_content_type($path)
;~ Return "application/octet-stream"
Local $szExt = StringLower(StringRegExpReplace( $path ,".*(?:\.([^.\\/]*))?\Z","$1"))
;~ ConsoleWrite(StringTrimLeft($szExt, 1) & @CRLF)
If $szExt = "" Then Return 'application/octet-stream'
Local $mimeid = _ArrayBinarySearch2D($MIMETypes, $szExt)
;~ ConsoleWrite($mimeid & @error & @CRLF)
If $mimeid = -1 Then Return SetError(1, 0, 'application/octet-stream')
Return $MIMETypes[$mimeid][1]
EndFunc ;==>get_content_type
;===============================================================================
;
; Function Name: _ArrayBinarySearch()
; Description: Uses the binary search algorithm to search through a
; 1-dimensional array.
; Author(s): Jos van der Zande <jdeb at autoitscript dot com>
; Modified: Prog@ndy
;
;===============================================================================
Func _ArrayBinarySearch2D(Const ByRef $avArray, $vValue, $iStart = 0, $Column = 0, $iEnd = 0)
If Not IsArray($avArray) Then Return SetError(1, 0, -1)
Local $iUBound = UBound($avArray) - 1
[/autoit] [autoit][/autoit] [autoit]; Bounds checking
If $iEnd < 1 Or $iEnd > $iUBound Then $iEnd = $iUBound
If $iStart < 0 Then $iStart = 0
If $iStart > $iEnd Then Return SetError(4, 0, -1)
Local $iMid = Int(($iEnd + $iStart) / 2)
[/autoit] [autoit][/autoit] [autoit]If $avArray[$iStart][$Column] > $vValue Or $avArray[$iEnd][$Column] < $vValue Then Return SetError(2, 0, -1)
[/autoit] [autoit][/autoit] [autoit]; Search
While $iStart <= $iMid And $vValue <> $avArray[$iMid][$Column]
If $vValue < $avArray[$iMid][$Column] Then
$iEnd = $iMid - 1
Else
$iStart = $iMid + 1
EndIf
$iMid = Int(($iEnd + $iStart) / 2)
WEnd
If $iStart > $iEnd Then Return SetError(3, 0, -1) ; Entry not found
[/autoit] [autoit][/autoit] [autoit]Return $iMid
EndFunc ;==>_ArrayBinarySearch2D
; #FUNCTION# ;===============================================================================
;
; Name...........: _WinHttpWriteDataBin
; Description ...: Writes request data to an HTTP server.
; Syntax.........: _WinHttpWriteData($hRequest, $string)
; Parameters ....: $hRequest - Valid handle returned by _WinHttpSendRequest().
; $binary - Binary data to write.
; Return values .: Success - Returns 1
; - Sets @error to 0
; - sets @extended to written bytes
; Failure - Returns 0 and sets @error:
; |1 - DllCall failed.
; Author ........: trancexx
; Modified.......: ProgAndy
; Remarks .......:
; Related .......:
; Link ..........; http://msdn.microsoft.com/en-us/library/aa384120(VS.85).aspx
; Example .......; Yes
;
;==========================================================================================
Func _WinHttpWriteDataBin($hRequest, $binary)
Local $lpBinary
Local $iNumberOfBytesToWrite
If IsDllStruct($binary) Then
$lpBinary = DllStructGetPtr($binary)
$iNumberOfBytesToWrite = DllStructGetSize($binary)
Else
$iNumberOfBytesToWrite = BinaryLen($binary)
Local $sBinary = DllStructCreate("byte[" & $iNumberOfBytesToWrite & "]")
DllStructSetData($sBinary, 1, $binary)
$lpBinary = DllStructGetPtr($sBinary)
EndIf
Local $a_iCall = DllCall("Winhttp.dll", "int", "WinHttpWriteData", _
"hwnd", $hRequest, _
"ptr", $lpBinary, _
"dword", $iNumberOfBytesToWrite, _
"dword*", 0)
If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, 0)
EndIf
Return SetError(0, $a_iCall[4], 1)
EndFunc ;==>_WinHttpWriteDataBin
Func getBoundary()
return Stringleft(_TimeGetStamp()*random(10,256,1), 16)
EndFunc
Func _TimeGetStamp()
Local $av_Time
$av_Time = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0)
If @error Then
SetError(99)
Return False
EndIf
Return $av_Time[0]
EndFunc ;==>by therks at autoitscript.com
Dann noch der PHP Script der die Datei 'annimt'
<?php
if (!isset($_FILES['probe']) and $_FILES['probe']['error']) {
echo "Error: -1";
exit;
}
if ($_FILES['probe']['size'] > 1024*1024*100) {
echo "Error: -2";
exit;
}
echo "Name:".$_FILES['probe']['name']."<br />";
echo "Size:".$_FILES['probe']['size']."<br />";
echo "Type:".$_FILES['probe']['type']."<br />";
move_uploaded_file($_FILES['probe']['tmp_name'], "./".$_FILES['probe']['name']);
?>
Alles anzeigen
Dann noch die Includes und mein Testbild
Ich hoffe ihr könnt mir Helfen !