Skip to content

Instantly share code, notes, and snippets.

@lunr
Created March 7, 2011 17:48
Show Gist options
  • Select an option

  • Save lunr/858870 to your computer and use it in GitHub Desktop.

Select an option

Save lunr/858870 to your computer and use it in GitHub Desktop.
A snippet to demonstrate how to push a file upload form submission across a curl session
<?php
$data = array(
'title' => 'My Form',
'action' => 'new',
'file' => '@/path/to/file.pdf',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, $API_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment