在php中使用curl命令
我一直对如何在 php 中使用curl 来运行这段代码感到困惑。
$ curl -F userfile=@Image_File_Name \
-F outputencoding="utf-8" \
-F outputformat="txt" \
http://Server_Address/cgi-bin/submit.cgi >result.txt
有人可以帮助我吗?我已经尝试过以下方法:
$cmd="curl -F userfile=$file_new \
-F outputencoding="utf-8" \
F outputformat=txt \
http://maggie.ocrgrid.org/cgi-bin/weocr/ocr_scene.cgi >result.txt"
exec($cmd,$result);
echo $result;
但它不起作用。
谢谢!
I've been stumped on how to use curl in php, for running this piece of code.
$ curl -F userfile=@Image_File_Name \
-F outputencoding="utf-8" \
-F outputformat="txt" \
http://Server_Address/cgi-bin/submit.cgi >result.txt
Could anyone help me? I've tried the following:
$cmd="curl -F userfile=$file_new \
-F outputencoding="utf-8" \
F outputformat=txt \
http://maggie.ocrgrid.org/cgi-bin/weocr/ocr_scene.cgi >result.txt"
exec($cmd,$result);
echo $result;
but it does not work.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要转义字符串中的双引号:
这应该可行。
exec
还会以数组形式返回其输出,该数组由换行符。所以echo $result;
将只打印“Array”。您可能想要 echo $result[0];或考虑使用反引号
或 < a href="http://www.php.net/manual/en/function.passthru.php" rel="nofollow">passthru
。不过,我建议使用 php cURL 库,而不是在单独的 shell 中执行 cURL: http:// /php.net/manual/en/book.curl.php
You need to escape your double quotes that are in the string:
That should work.
exec
also returns it's output in an array separated by newlines. Soecho $result;
will just print 'Array'. You may want to echo $result[0]; or consider usingbackticks
orpassthru
.Rather than executing the cURL in a separate shell though, I recommend the php cURL library: http://php.net/manual/en/book.curl.php
libcurl 会更适合你 - 它提供了你需要的所有功能和错误处理需要在 PHP 中使用 cURL。
libcurl will suit you better - it provides all the functions and error handling you'll need for using cURL in PHP.