[Lazarus] Translating php://input into fcl-web

silvioprog silvioprog at gmail.com
Sat Aug 23 22:18:56 CEST 2014


On Sat, Aug 23, 2014 at 3:12 PM, "Leonardo M. Ramé" <l.rame at griensu.com>
wrote:

> Hi, I'm trying to translate this PHP code to fcl-web (actually
> brookframework):
>
> <?php
> $content = file_get_contents('php://input');
> $fh = fopen('output.wav', 'w') or die("can't open file");
> fwrite($fh, $content);
> fclose($fh);
> ?>
>
> The difficult part is the line with "file_get_contents('php://input')",
> it contains the whole POST content as binary.
>
> What I already did was this:
>
> procedure TActAudio.Post;
> var
>   lWav: TMemoryStream;
> begin
>   lWav := TMemoryStream.Create;
>   try
>     lWav.Write(HttpRequest.Content[1], HttpRequest.ContentLength);
>     lWav.Position:= 0;
>     lWav.SaveToFile('/tmp/output.wav');
>   finally
>     lWav.Free;
>   end;
> end;
>
> But the output.wav result is corrupt, while the php one is correct.
>
> Any hint?.
>
> Regards,
>

Worked fine here:

procedure TMyAction.Post;
begin
  with TFileStream.Create('out.txt', fmCreate) do
  try
    Write(TheRequest.Content[1], TheRequest.ContentLength);
  finally
    Free;
  end;
end;

POST /cgi1.br HTTP/1.1

{"key1":"value1","key2":"value2"}

out.txt:
{"key1":"value1","key2":"value2"}

Or:

procedure TMyAction.Post;
begin
  with TMemoryStream.Create do
  try
    Write(TheRequest.Content[1], TheRequest.ContentLength);
    SaveToFile('post.txt');
  finally
    Free;
  end;
end;

P.S.: php://input is not available with enctype="multipart/form-data".

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140823/ac22f440/attachment-0003.html>


More information about the Lazarus mailing list