Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用cURL而不是exec()?_Php_Curl - Fatal编程技术网

Php 如何使用cURL而不是exec()?

Php 如何使用cURL而不是exec()?,php,curl,Php,Curl,我得到一个错误: 警告:exec()由于安全原因已被禁用 对于下面的代码,我想知道如何在不使用exec()的情况下解决这个问题吗 试试这个: $url = 'http://maggie.ocrgrid.org/cgi-bin/weocr/ocr_scene.cgi'; $filename = 'test.jpg'; // postfields $data = array( 'userfile' => '@'.realpath($filename) ); $fp1 = fopen

我得到一个错误:

警告:
exec()
由于安全原因已被禁用

对于下面的代码,我想知道如何在不使用
exec()
的情况下解决这个问题吗

试试这个:

$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;

如果有办法的话,那就不太安全了。你能不能自己做呢?为什么不直接使用curl呢?PHP在curl周围有一个包装器库。如果禁用了
exec
,那么
curl
,您是否在共享托管网站上?
$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;