-1

I get the error:

Warning: exec() has been disabled for security reasons

For the following code, any ideas of how I could workaround this without using exec()?

$file = 'test.jpg';
$cmd  = 'curl -F userfile=$file ' .
        '-F outputencoding="utf-8" ' .
        '-F outputformat="txt" ' .
        'http://maggie.ocrgrid.org/cgi-bin/weocr/ocr_scene.cgi >result.txt';
exec($cmd, $result);
echo $result;
6
  • 2
    If there was a way around that, it wouldn't be very secure. Commented May 12, 2013 at 3:01
  • 4
    Can you not do this natively? php.net/manual/en/book.curl.php Commented May 12, 2013 at 3:02
  • 2
    Why don't use curl directly? Commented May 12, 2013 at 3:02
  • PHP has a wrapper library around cURL. Commented May 12, 2013 at 3:03
  • Pretty sure if exec is disabled, so is curl, are you on a shared hosting website? Commented May 12, 2013 at 3:09

1 Answer 1

0

Try this:

$url = 'http://maggie.ocrgrid.org/cgi-bin/weocr/ocr_scene.cgi';
$filename = 'test.jpg';

// postfields
$data = array(
    'userfile' => '@'.realpath($filename)
);

$fp1 = fopen('res_error.txt','w');
$fp2 = fopen('res_header.txt','w');

// cURL
$ch = curl_init();
curl_setpot_array($ch, array(
    CURLOPT_URL            => $url  ,
    CURLOPT_POSTFIELDS     => $data ,
    CURLOPT_CONNECTTIMEOUT => 60    ,
    CURLOPT_HEADER         => false ,
    CURLOPT_RETURNTRANSFER => true  ,
    CURLOPT_POST           => true  ,
    CURLOPT_VERBOSE        => true  ,
    CURLOPT_STDERR         => $fp1  ,
    CURLOPT_WRITEHEADER    => $fp2  ,
));
$res = curl_exec($ch);

fclose($fp1);
fclose($fp2);

echo $res;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.