Article View: borland.public.cppbuilder.internet.socket
Article #1786Re: Upload a file using PHP and http->Post ?
From: Nicholas Wilson
Date: Thu, 26 Oct 2006 05:12
Date: Thu, 26 Oct 2006 05:12
74 lines
3569 bytes
3569 bytes
Thanks for that, may have been a case of staring for so long I could not see
the obvious. I
have been cutting and pasting code from all over the place so I have
obviously made a mistake.
I could not see where to download that version from ?
I am getting 9.0.15 from the indy site.
I will make the changes that you have pointed out see how I go. the memory
leak was intentional ( this is just testing at the moment);
cheers
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:4540405a$1@newsgroups.borland.com...
>
> "Nicholas Wilson" <nicholasjohnwilson@gmail.com> wrote in message
> news:45400f1d@newsgroups.borland.com...
>
> > I am using the 9.15 version of the Indy component.
>
> That is a very old version. The current snapshot of Indy 9 is 9.0.50.
You
> should consider upgrading.
>
> > this is the sample code I cannot get to work.
>
> It does not work because you are uploading the wrong stream to the server.
> You are allocating a TMemoryStream named _params that you do not fill it
> with any data but you ar uploading it anyway. You are then allocating a
> TIdMultiPartFormDataStream named _idmpfd that you are not uploading when
you
> should be. You need to get rid of the _params stream altogether and
upload
> the _idmpfd stream instead.
>
> Not only that, but you are filling in the TIdMultiPartFormDataStream
> incorrectly anyway. You should not be adding the file name and file data
as
> separate fields. They belong to a single field in the HTML form, so you
> have to add them to the stream as a single field.
>
> Also, your code has memory leaks in it. You need to free the streams you
> allocate.
>
> Try this instead:
>
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> AnsiString _html;
> TIdMultiPartFormDataStream *_idmpfd = new
> TIdMultiPartFormDataStream;
> try
> {
> ldhttp->Request->ContentType = _idmpfd->RequestContentType;
>
> // AddFile() calls GetMIMETypeFromFile() when no ContentType
is
> specified
> _idmpfd->AddFile("userfile", "formsource.h", "");
>
> _html = ldhttp->Post ("http://192.168.87.69/upload.php",
> _idmpfd);
> }
> __finally {
> delete _idmpfd;
> }
> ShowMessage(_html);
> }
>
>
> Gambit
>
>
Technical Details
Message-ID:
<45404395@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.code-werk.net!news.soft-gems.net!open-news-network.org!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mailReferences:
<4535c1b4@newsgroups.borland.com> <4535cae8@newsgroups.borland.com> <45400f1d@newsgroups.borland.com> <4540405a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,3eee350dd19e6632 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Nicholas Wilson" <nicholasjohnwilson@gmail.com> From: "Nicholas Wilson" <nicholasjohnwilson@gmail.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <4535c1b4@newsgroups.borland.com> <4535cae8@newsgroups.borland.com> <45400f1d@newsgroups.borland.com> <4540405a$1@newsgroups.borland.com> Subject: Re: Upload a file using PHP and http->Post ? Date: Thu, 26 Oct 2006 15:12:52 +1000 Lines: 76 Organization: None X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 NNTP-Posting-Host: 202.138.213.226 Message-ID: <45404395@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1161839509 202.138.213.226 (25 Oct 2006 22:11:49 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!news.code-werk.net!news.soft-gems.net!open-news-network.org!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail