akalie Posted March 23, 2011 Share 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)) Link to comment Share on other sites More sharing options...
ProgAndy Posted March 23, 2011 Share 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 Link to comment Share on other sites More sharing options...
Tvern Posted March 23, 2011 Share 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. Link to comment Share on other sites More sharing options...
akalie Posted March 23, 2011 Author Share Posted March 23, 2011 Thanx, ProgAndy))) I'm idiot... And yes, the FileReade code part was not right too... Sorry my English)) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now