Automation REST API - Upload a new file for indexing

Warning! Do NOT use this if you have already changed / updated your schema.xml or solrconfig.xml files!!!
Only use it on new indexes that have schema.xml and solrconfig.xml intact.

IMPORTANT: In order to import data from a CSV file , please follow this tutorial as this will only index the contents and metadata of your uploaded files

Sample PHP code to upload to the REST API

    $target_url = '';
    $file_name_with_full_path = realpath('./document.pdf');
    if (function_exists('curl_file_create')) {
        $cFile = curl_file_create($file_name_with_full_path);
    } else {
        $cFile = '@' . realpath($file_name_with_full_path);

    // These are the extra fields that the REST API will expect
    $post = array(
      'api_key'   => 'YOUR_OPENSOLR_REST_API_KEY',
      // Optionally add a URL to index alongside your file.
      'url'       => '',
      'userfile'  => $cFile

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$target_url);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $result=curl_exec ($ch);
    curl_close ($ch);
    echo $result;

Sample HTML Form

    <form method="post" action="" enctype="multipart/form-data" />

      <label for="core_name">Index Name:</label>
      <input type="text" name="core_name" size="65" /><br />

      <label for="email">Opensolr Registration Email:</label>
      <input type="text" name="email" size="65" /><br />

      <label for="api_key">Opensolr API Key:</label>
      <input type="text" name="api_key" size="65" /><br />

      <label for="api_key">Optional URL to index:</label>
      <input type="text" name="url" size="65" /><br />

      <label for="userfile">Document / File to Index:</label>
      <input type="file" name="userfile" /><br /><br />

      <input type="submit" value="     Upload File     ">