【问题标题】:how i can use this curl command in php?我如何在 php 中使用这个 curl 命令?
【发布时间】:2017-07-10 15:24:20
【问题描述】:

我正在尝试在我的网站端口 80 上发送用户输入的文件,并使用以下 curl 命令发送该文件以在服务器上执行:

curl -v --form input=@./file.pdf localhost:8080/processHeaderDocument -o ./file.xml

我尝试这样做,但没有任何反应

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/");
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);

curl_close($ch);

如何在 php 中使用这个命令?通过80端口向8080发送文件会不会出现问题?

【问题讨论】:

    标签: php curl port


    【解决方案1】:

    试试下面的代码希望能解决你的问题。

    // initialise the curl request
    $request = curl_init('http://example.com/');
    
    // send a file
    curl_setopt($request, CURLOPT_POST, true);
    curl_setopt(
        $request,
        CURLOPT_POSTFIELDS,
        array(
          'file' => '@' . realpath('example.txt')
        ));
    
    // output the response
    curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
    echo curl_exec($request);
    
    // close the session
    curl_close($request);
    

    下面是链接。 http://code.stephenmorley.org/php/sending-files-using-curl/

    【讨论】:

    • 我尝试了这段代码,似乎服务器找不到文件路径并出现此错误 [错误] org.grobid.service.process.GrobidRestProcessFiles:发生意外异常:java.lang.NullPointerException [ ERROR] org.grobid.core.utilities.IOUtilities:删除临时文件时出错:java.lang.NullPointerException
    猜你喜欢
    • 1970-01-01
    • 2015-02-16
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-17
    • 2023-01-15
    • 1970-01-01
    • 2013-08-24
    相关资源
    最近更新 更多