Jump to content

problems with 0x00 in string


Recommended Posts

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 by akalie

Sorry my English))

Link to comment
Share on other sites

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

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

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...