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

curl-and-php

Uploading a file through curl + php

From: Matt Parkins <matt_at_parkins.uk.net>
Date: Thu, 16 Dec 2004 16:44:50 -0000

 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I want to use Curl to upload a file to a location on another machine.
  Am I missing something? I can do the following successfully in a
form on a .html page but when I try to do it in .php although
processreturndata.php is called the $_FILES superglobal is empty,
and, as below, if CURLOPT_UPLOAD/INFILE/INFILESIZE are specified then
the POST fields come through blank! Like I said, it all comes
through fine if I use a form in a HTML page (the file is about 47
bytes long):

$curl =
curl_init(_BACKOFFICE_ADDRESS."functions/processreturndata.php");

$postdata = array();
$postdata['return_filesize'] = $return_filesize;
$postdata['return_debug'] = $return_debug;
$postdata['return_status'] = $return_status;

$file = fopen($return_filename, "r");

$str = '';
foreach($postdata as $key => $val)
        $str .= $key . '=' . urlencode($val) . '&';

curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, substr($str, 0, -1));
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_UPLOAD, 1);
curl_setopt($curl, CURLOPT_INFILE, $file);
curl_setopt($curl, CURLOPT_INFILESIZE, $return_filesize);

curl_exec($curl);

$succeeded = (curl_errno($curl) == 0);

Matt Parkins

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.1

iQA/AwUBQcG7gitTzPm4J+DXEQJfGQCgudTTazgpYVnfPOq0of8AuAMbZXgAoPdK
uK5OgEL/7pTS/E8hW45Nv5vu
=l2PQ
-----END PGP SIGNATURE-----
Received on 2004-12-16