cURL

Using PHP and CURL to do an HTML file POST

After scouring the internet to find out how to do multipart post operations and finding nothing nothing, I decided to save someone else some time. The trick is that @ before the file name:

<?php
$fullflepath
= 'C:\temp\test.jpg';
$upload_url = 'http://www.example.com/uploadtarget.php';
$params = array(
 
'photo'=>"@$fullfilepath",
 
'title'=>$title
);       

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
?>

Originally posted here: http://drewish.com/blogger/archives/2005/01/27/using_php_and_curl_to_do_...

Enabling PHP Modules

Phlickr uses two several of PHP5's extensions, CURL and SimpleXML. In some cases these two extensions may not be enabled by default.

The first step is verify that the modules are not already being loaded. You view a list of the modules using the following command:

Downloading Democracy Now! automatically

Here's a PHP script I wrote for the radio station to download each day's copy of Democracy Now!. This requires that the PHP cURL extension be installed.

Syndicate content