【问题标题】:curl statement to PHP enabling use of Apache TIKA使用 Apache TIKA 的 PHP 的 curl 语句
【发布时间】:2015-05-09 05:03:27
【问题描述】:

我已经安装了Apache TIKA和TIKAJAXRS

我打算将它与 PHP(TIKA 即服务)一起使用。我需要提取 URL 的内容,然后操作返回的内容。要使用 TIKA 作为服务,文档说

可以使用带有TikaJAXRS 的远程文件,方法是先通过其 URL 下载它,然后将其通过管道传输到相应的服务:

$ curl -s "http://url/to/my.file" | curl -X PUT -T - <<TIKA ADDRESS>>/meta
$ curl -s "http://url/to/my.file" | curl -X PUT -T -<<TIKA ADDRESS>>/tika 

我无法使用 PHP cURL 将上述语句翻译成 PHP。

【问题讨论】:

    标签: php apache curl apache-tika


    【解决方案1】:

    基于PHP curl tutorial、this Stackoverflow question 和Apache Tika Server documentation,你应该做的是:

    // Set where to connect to
    $ch = curl_init("http://localhost:9998/meta");
    // Request will be a PUT
    curl_setopt($ch, CURLOPT_PUT, 1);
    // Set the file to send
    $file_path_str = "/path/to/my/file.txt";
    $fh_res = fopen($file_path_str, 'r');
    curl_setopt($ch, CURLOPT_INFILE, $fh_res);
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path_str));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // Send the request
    $curl_response_res = curl_exec ($ch);
    fclose($fh_res);
    
    // Do something with the result
    echo "<p>Tika says:</p>";
    echo "<pre>" + $curl_response_res + "</pre>";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 1970-01-01
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多