Automation REST API - Upload or overwrite a zip archive containing all your solr configuration files







Sample PHP code to upload to the REST API

  
    $target_url = 'https://opensolr.com/solr_manager/api/upload_zip_config_files';
    
    //This needs to be the full path to the file you want to send.
    $file_name_with_full_path = realpath('./file.zip'); // Zip archive containing your schema.xml and other solr config files.
    // If this file exists it will be updated. If it doesn't exist, it will be created.


      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(
      'email' => 'YOUR_OPENSOLR_REGISTERED_EMAIL_ADDRESS',
      'api_key' => 'YOUR_OPENSOLR_REST_API_KEY',
      'core_name' => 'NAME_OF_THE_CORE_YOU_WANT_TO_UPLOAD_THIS_FILE_FOR',
      '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="https://opensolr.com/solr_manager/api/upload_config_file" enctype="multipart/form-data" />
      
      <label for="core_name">Core 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="userfile">File To Upload:</label>
      <input type="file" name="userfile" /><br /><br />
      
      <input type="submit" value="     Upload File     ">
    
    </form>
  



Review us on Google Business
Close Check out the Fully Automated Solr server setup for Drupal & WordPress.