Reputation: 1
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!
Upvotes: 0
Views: 1356
Reputation: 141907
You need to escape your double quotes that are in the string:
$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"
That should work. exec
also returns it's output in an array separated by newlines. So echo $result;
will just print 'Array'. You may want to echo $result[0]; or consider using backticks
or passthru
.
Rather than executing the cURL in a separate shell though, I recommend the php cURL library: http://php.net/manual/en/book.curl.php
Upvotes: 1