cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: curl -data-binary

From: Kevin Carothers <kevindotcar_at_gmail.com>
Date: Thu, 31 Aug 2006 10:45:40 -0700

On 8/31/06, Tonny Han <tonnyhan2002_at_163.com> wrote:
>
> hi ,i am a beginer to html/asp....
>
> i use curl in my work.
> i want to upload a file to my website , i use the command like below
> curl --data-binary @myfile http://localhost/recvfile
>
> can anybody give me a "recvfile" file that i can receive and save the
> uploaded file data ?
>
> php/perl/asp are all ok.
> thx a lot.
>

Hi Tony,
Apologies in advance for any inaccuracies.

1. First (in case you haven't already) you have to configure your website
to allow HTTP Proxies - I don't know how to do it in IIS but it;s pretty
easy with Apache - look for lines like this;

   LoadModule proxy_module modules/mod_proxy.so
   LoadModule proxy_connect_module modules/mod_proxy_connect.so
   LoadModule proxy_http_module modules/mod_proxy_http.so

2. You have to write a Curl cmd to ask for a Multipart submit and send it
to your website- basically faking out this;
<form ENCTYPE="multipart/form-data" method=POST ACTION="
http://mywebsite/cgi-bin/UploadFile.pl" >
<INPUT TYPE=FILE Name=MyFile>
<INPUT TYPE=SUBMIT NAME=subFile Value=Submit>
</form>

3. You have to write "Uploadfile.pl" - it should basically be a program
that "handles" the file on your web server- looking for the input (that you
gave above) - The following are pretty common;

if ($ENV{'REQUEST_METHOD'} ne "POST") {
  print "Status: 405 Method Not Allowed\n" .
        "Content-Type: text/html\nAllow: POST\n\n" .
        "<html><head><title>405 Method Not
Allowed</title></head><body><h1>Your web browser $ENV{'HTTP_USER_AGENT'}
used request method $ENV{'REQUEST_METHOD'}. This behavior may be a bug in
your browser. To convert a graphic image, request method must be POST. Try
again.</h1></body></html>\n";
  exit 0;
}

if ($ENV{'CONTENT_TYPE'} !~ /multipart\/form-data/) {
  print "Cache-Control: no-cache\nPragma: no-cache\n" .
        "Content-Type: text/html\n\n" .
        "<html><body>Your web browser cannot upload files.
Sorry.</body></html>";
  exit 0;
}

-------------
Next, read the passed file contents;
$query = new CGI;
my($filename) = $query->param('MyFile');
[---]
binmode($filename);
$lbytes=read($filename,$l_buffer,$ENV{'CONTENT_LENGTH'});

### From here- it's up to you what you want to do with the file

-------------

HTH

KC
Received on 2006-08-31