|
[云开发]
使用PHP curl上传图片总是提示Errno:couldn't open file
[复制链接]
<?php
function getMillisecond() {
list($s1, $s2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000);
}
function intiCurl($method,$class,$content,$id){
$time = getMillisecond();
$AppID = 'xxxx';
$AppKey = 'xxxxxxx';
$AppPath = 'https://d.apicloud.com/mcm/api/file';
$shaKey = sha1($AppID.'UZ'.$AppKey.'UZ'.$time).'.'.$time;
$ch = curl_init();
$timeout = 30;
$headerinfo = array(
//'Content-Type:application/json',
'application/x-www-form-urlencoded',
'X-APICloud-AppId:'.$AppID,
'X-APICloud-AppKey:'.$shaKey,
);
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ($ch, CURLOPT_URL, $AppPath);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headerinfo);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$post_data = array("file" =>"@ ","filename"=>"{{67.jpg}}","type"=>"{{jpg}}"
);
print_r($post_data);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_data);
$file_contents = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Errno:'.curl_error($ch)."<Br/>";//捕抓异常
}
curl_close($ch);
return $file_contents;
}
echo intiCurl('POST','','xxxxxx','');
?>
|
|