function rec_transfer_upload_preference in Recommender API 6.3
Same name and namespace in other branches
- 7.4 rec_transfer/rec_transfer.module \rec_transfer_upload_preference()
- 7.5 rec_transfer/rec_transfer.module \rec_transfer_upload_preference()
1 call to rec_transfer_upload_preference()
- rec_transfer_upload in rec_transfer/
rec_transfer.module
File
- rec_transfer/
rec_transfer.module, line 238 - This is the module file for Recommender Data Transfer
Code
function rec_transfer_upload_preference($filename, $options = array()) {
// TODO: need to check curl first.
// TODO: could consider to use stream_ copy_ to_ stream instead. drupal_http_client() is not good here because we need to read big file into memory first.
$ch = curl_init();
// curl_setopt($ch, CURLOPT_HEADER, FALSE); // TRUE to include the header in the output.
// curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, "Drupal (Recommender)");
curl_setopt($ch, CURLOPT_URL, variable_get('rec_transfer_endpoint', '') . '/upload');
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
// setup compression
curl_setopt($ch, CURLOPT_POST, TRUE);
// same as <input type="file" name="file_box">
$post = array(
'preference' => "@{$filename}",
) + $options;
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$upload_success = $response && curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200;
curl_close($ch);
return $upload_success;
}