Skip to content

Instantly share code, notes, and snippets.

@coolbung
Last active February 10, 2016 16:25
Show Gist options
  • Save coolbung/40e04f71fa268cb154f3 to your computer and use it in GitHub Desktop.
Save coolbung/40e04f71fa268cb154f3 to your computer and use it in GitHub Desktop.
Upload files using Joomla JHttp
$path = realpath('/absolute/path/to/file.jpg');
$upload_path = new \CURLFile($path);
$url = 'http://example.com/upload';
//$post_data['foo'] = 'bar';
$post_data['file'] = $upload_path;
//$headers['user-id'] = 'imli';
$headers['Content-Type'] = 'multipart/form-data';
$options = new JRegistry;
$http = JHttpFactory::getHttp($options, 'curl');
$op = $http->post( $url, $post_data, $headers );
print_r($op);
print_r($http);
jexit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment