akalie 0 Posted March 23, 2011 (edited) Good day! I have a function to upload a .jpg file. The PHP script can't work with the file then "0x00" char is stripped from the file... And when the "0x00" char is included the file won't even be uploaded... $upfile = "picture.jpg"; if not FileExists($upfile) Then return -1 EndIf $handle = FileOpen($upfile,16) $fileread = '' While 1 $t = FileRead($handle, 1) If @error Then ExitLoop $fileread = StringToBinary($t) WEnd FileClose($handle) $boundary = '----------Omt4atmtaOmNtmo' $data = "--" & $boundary & @LF & _ 'Content-Disposition: form-data; name="method"' & @lf & @lf & 'post' & @lf & _ "--" & $boundary & @lf & _ 'Content-Disposition: form-data; name="file"; filename="picture.jpg"' & @LF & _ 'Content-Type: image/pjpeg' & @LF & @LF & _ $fileread & @lf & _ '--'&$boundary&'--' & @lf& @lf _WinHttpAddRequestHeaders($h_openRequest,"Accept-Encoding: identity") _WinHttpAddRequestHeaders($h_openRequest,"Content-Type: multipart/form-data; boundary=" & $boundary) _WinHttpSendRequest($h_openRequest,$WINHTTP_NO_ADDITIONAL_HEADERS, $WINHTTP_NO_REQUEST_DATA, StringLen($data), 0) _WinHttpWriteData($h_openRequest, $data) Can anyone show how to avoid this? Thanks! Edited March 23, 2011 by akalie Sorry my English)) Share this post Link to post Share on other sites
ProgAndy 88 Posted March 23, 2011 You have to use _WinHttpWriteData with $iMode set to 1 I think. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Share this post Link to post Share on other sites
Tvern 11 Posted March 23, 2011 Call me crazy, but the FileRead part of the script seems to make no sense: I believe $t is already binary when read and the content of $fileread is constantly replaced with the binary representation of $t, instead of appending to it. At the end of the loop $fileread will only have a binary representation of the (already binary representation) of the last byte of the file won't it? Try to replace that part of your script with this instead: $handle = FileOpen($upfile,16) $fileread = FileRead($handle) FileClose($handle) For the binary upload I try ProgAndy's suggestion. Share this post Link to post Share on other sites
akalie 0 Posted March 23, 2011 Thanx, ProgAndy))) I'm idiot... And yes, the FileReade code part was not right too... Sorry my English)) Share this post Link to post Share on other sites