Skip to content

Instantly share code, notes, and snippets.

@bryjbrown
Last active March 25, 2020 13:00
Show Gist options
  • Save bryjbrown/ee5bdb793609473e63a4fbefa26b5f96 to your computer and use it in GitHub Desktop.
Save bryjbrown/ee5bdb793609473e63a4fbefa26b5f96 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
// User Settings
$doi_prefix = '10.00000';
$username = 'username';
$password = 'password';
$file_path = '/path/to/file.xml';
$test_mode= TRUE;
if ($test_mode) {
$url = 'https://test.crossref.org/servlet/deposit';
} else {
$url = 'https://doi.crossref.org/servlet/deposit';
}
$curlCh = curl_init();
curl_setopt($curlCh, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlCh, CURLOPT_POST, true);
curl_setopt($curlCh, CURLOPT_HEADER, true);
curl_setopt($curlCh, CURLOPT_URL, $url);
curl_setopt($curlCh, CURLOPT_SAFE_UPLOAD, true);
$cfile = new CURLFile($file_path);
$data = [
'operation' => 'doMDUpload',
'usr' => $username,
'pwd' => $password,
'mdFile' => $cfile,
];
curl_setopt($curlCh, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlCh, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curlCh);
print_r($response);
print_r(curl_getinfo($curlCh, CURLINFO_HTTP_CODE));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment