0

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!

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

libcurl will suit you better - it provides all the functions and error handling you'll need for using cURL in PHP.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.