Home >Backend Development >PHP Tutorial >php怎么做api上传文件接口
php如何做api上传文件接口?
现在要是实现上传wav,jpg等文件上传api接口,怎么上传,请高手们提供代码参考
------解决方案--------------------
http://www.w3school.com.cn/php/php_file_upload.asp
------解决方案--------------------
$file = realpath('gif/1.gif'); //要上传的文件<br />$fields['f'] = '@'.$file;<br /><br />$ch = curl_init(); <br />curl_setopt($ch, CURLOPT_URL,"你的api接口"); <br />curl_setopt($ch, CURLOPT_POST, 1 );<br />curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);<br /><br />curl_exec ($ch); <br />curl_close ($ch); <br />