You are here

function apachesolr_file_extract in Apache Solr File 7

1 call to apachesolr_file_extract()
apachesolr_file_index_solr_document in ./apachesolr_file.module

File

./apachesolr_file.module, line 112

Code

function apachesolr_file_extract($env_id, $file) {
  $env = apachesolr_environment_load($env_id);
  $url = $env['url'] . '/update/extract/?extractOnly=true&wt=phps&extractFormat=text';
  $filepath = drupal_realpath($file->uri);

  // Construct a multi-part form-data POST body in $data.
  $boundary = '--' . md5(uniqid(REQUEST_TIME));
  $data = "--{$boundary}\r\n";

  // The 'filename' used here becomes the property name in the response.
  $data .= 'Content-Disposition: form-data; name="file"; filename="extracted"';
  $data .= "\r\nContent-Type: application/octet-stream\r\n\r\n";
  $data .= file_get_contents($filepath);
  $data .= "\r\n--{$boundary}--\r\n";
  $headers = array(
    'Content-Type' => 'multipart/form-data; boundary=' . $boundary,
  );
  $options = array(
    'method' => 'POST',
    'headers' => $headers,
    'data' => $data,
  );
  $request = drupal_http_request($url, $options);
  $response = @unserialize($request->data);
  return $response;
}