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

curl-and-php

Using php/curl to send a file to HTTPS via post

From: Aaron Axelsen <lists_at_frozenpc.net>
Date: Wed, 26 Jul 2006 12:33:02 -0500

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
I am trying to use PHP to post a file to a HTTPS link. It works from
the command line using the following command:

curl -s -F file=\@/path/to/my/file https://path/to/my/server

I am having trouble try to replicate this same command using the
php. Any suggestions?

// Build Post Fields
$postfields = array("file" => "@$fileIn"); // Full system path to the
file

$pushUrl = curl_init($uploadUrl);
curl_setopt($pushUrl, CURLOPT_VERBOSE, 1);
curl_setopt($pushUrl, CURLOPT_FAILONERROR, 1);
curl_setopt($pushUrl, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($pushUrl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($pushUrl, CURLOPT_POST, true);
curl_setopt($pushUrl, CURLOPT_POSTFILEDS, $postfields);
$output = curl_exec($pushUrl);
$error = curl_error($pushUrl);
$http_code = curl_getinfo($pushUrl ,CURLINFO_HTTP_CODE);

curl_close($pushUrl);

print "<br/>";
print $http_code;
print "<br /><br />$output";
if ($error) {
     print "<br /><br />$error";
}

- --
Aaron Axelsen
lists_at_frozenpc.net

Great hosting, low prices. Modevia Web Services LLC --
http://www.modevia.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFEx6dNuucONIvD0AMRAtfVAKCc9hBHLHCTq1m/ZBe/TWnwBPFaawCffpFm
hBRnl6l0nrwmSGUrHDuyesY=
=F9Ra
-----END PGP SIGNATURE-----

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