cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: sftp

From: Pete James <Pete_James_at_advanis.ca>
Date: Fri, 30 Nov 2001 10:19:27 -0700

Simply pointing to an obvious location is not going to do him much good,
as there is very little documentation anywhere on multipart curl
transfers.

I was researching the exact same issue about two months ago, and the
only thing I found was a little posting on php.net under one of the curl
articles. As it turns out, it's very easy, and I'd love to write a
helper article on this subject, but I don't have a medium or the feeling
that I'm an authority on it. I have forwarded him an example, and I
will include it here for any other curious folks.

----x----

(Using a file upload box on a web page)

When the user selects a file and submits the form, this code will post
to itself, which in effect uploads the file to the web server's temp
directory. $sampfile contains the temporary file name in this
directory. You then repost it by using an associative array, prefixing
the name of the file with an @ sign. This will post it to the server
specified in $APP. You will then get a variable on $APP called
$sampfile that will contain the temp file name on that server. You
could pass it around all day like this. Check out PHP.net under the
CURL section. There isn't much useful info there for this type of stuff,
but there is one or two very useful postings under the articles.

Good luck.
Pete.

<?php
  if (isset($sampfile))
  {
     $ch = curl_init($APP);
     curl_setopt($ch, CURLOPT_POSTFIELDS, array
('sampfile'=>"@$sampfile"));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $postResult = curl_exec($ch);
     curl_close($ch);
     print "$postResult";
  }
  else
  {
     print "<form enctype=\"multipart/form-data\" "
                . "action=\"$PHP_SELF\" method=\"post\" >\n";

     print "</form>";
}

?>

----x----

Pete.

Daniel Stenberg wrote:
>
> On Thu, 29 Nov 2001, Roger Thomas wrote:
>
> > i am interested in writing a script to upload file from server A to
> > server B using php and curl.
> >
> > i am just 30 minutes old with curl. please advise, appreciate if code
> > fragment included.
>
> http://curl.haxx.se/libcurl/php/
>
> --
> Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/

-- 
Pete James, Advanis
Received on 2001-12-01