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;