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

curl-and-php

RE: PHP script to accept PUT from curl on Apache

From: David Barrett <dbarrett_at_quinthar.com>
Date: Sun, 26 Mar 2006 21:22:40 -0800

Hi Tedd, thanks for asking. No, I'm not trying to use FTP, I'm trying to
use an HTTP PUT request. This is like a cleaner version of a POST file
upload (well, clean if I can get it to work, that is).

-david

> -----Original Message-----
> From: curl-and-php-bounces_at_cool.haxx.se [mailto:curl-and-php-
> bounces_at_cool.haxx.se] On Behalf Of tedd
> Sent: Sunday, March 26, 2006 9:17 PM
> To: curl with PHP
> Subject: Re: PHP script to accept PUT from curl on Apache
>
> Hi:
>
> I'm not an expert by any means, but are you trying to ftp a file to a
> site with a curl?
>
> tedd
>
>
> >I hate to ask this basic question, but scouring the net and mailing list
> >isn't turning up what I need. Basically, how do I use the curl command
> line
> >to PUT a file to a PHP script in Apache? I've been able to get so far
> that
> >the PHP script creates an empty file with the correct name, but I'm
> stumped
> >how to get the file content. I can't tell if the problem is in my PHP
> >script (probable), in my use of curl (probable), or in curl itself
> (highly
> >improbable). Can you offer any tips on what I'm doing wrong?
> >
> >Here's what I've done so far:
> >
> >1) Configure Apache to accept a PUT command (Apache/2.0.54):
> >
> > Alias /putstuff /htdocs/putstuff
> > <Directory /htdocs/putstuff>
> > Options ExecCGI
> > AllowOverride All
> > Order allow,deny
> > Allow from all
> > Script PUT /put.php
> > </Directory>
> >
> >2) Create 'put.php' script (PHP/4.4.2):
> >
> > <?php
> > $totalWritten = 0;
> > $inFP = @fopen( "php://stdin", "rb" );
> > $outFP = @fopen( basename( $REQUEST_URI ), "wb" );
> > while( $data = fread( $inFP, 1024 ) )
> > {
> > fwrite( $outFP, $data );
> > $totalWritten += strlen( $data );
> > }
> > fclose($inFP);
> > fclose($outFP);
> >
> > if( $totalWritten ) header( "HTTP/1.0 200 Success" );
> > else header( "HTTP/1.0 404 Failed" );
> > ?>
> >
> >3) Upload file from command line (Win32, no-SSL binary, 7.15.1)
> >
> > C:\>dir test
> > Volume in drive C is DriveC
> > Volume Serial Number is F0ED-F121
> >
> > Directory of C:\
> >
> > 03/26/2006 02:15 AM 779 test
> > 1 File(s) 779 bytes
> > 0 Dir(s) 489,162,752 bytes free
> >
> > C:\>curl -i -T test http://myserver/putstuff/
> > HTTP/1.1 100 Continue
> >
> > HTTP/1.1 404 Failed
> > Date: Mon, 27 Mar 2006 01:34:13 GMT
> > Server: Apache
> > X-Powered-By: PHP/4.4.2
> > Content-Length: 0
> > Content-Type: text/html
> >
> >
> > C:\>
> >
> >4) Check to see if the file arrived:
> >
> > [root_at_myserver]# ls -latr
> > total 16
> > drwxr-xr-x 18 admin admin 4096 Mar 26 15:09 ..
> > -rw-r--r-- 1 admin admin 13 Mar 26 15:23 index.html
> > -rw-r--r-- 1 admin admin 926 Mar 26 16:35 put.php
> > -rw-r--r-- 1 apache apache 0 Mar 26 17:15 test
> > drwxrwxrwx 2 admin admin 4096 Mar 26 17:15 .
> > [root_at_myserver]#
> >
> >
> >As you can see from this command sequence, it succeeds in:
> >
> > a) Accepting the PUT request
> > b) Directing to the PHP script
> > c) Getting the right filename
> > d) Opening an output file
> >
> >(Also, though I've removed the error checking in the example above, it's
> >able to open the 'stdin' handle without trouble.)
> >
> >But I'm stumped as to why it won't write the file content itself. Any
> >advice? Thanks!
> >
> >-david
> >
> >
> >_______________________________________________
> >http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>
> --
> --------------------------------------------------------------------------
> ------
> http://sperling.com
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-03-27