php curl binary 文件上传
public function upload($url = "", $file_path = "") { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => , CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CUSTOMREQUEST => PUT, CURLOPT_POSTFIELDS => file_get_contents($file_path), CURLOPT_HTTPHEADER => array( Content-Type: application/octet-stream ), )); $output = curl_exec($curl); $error = curl_errno($curl); if ($error) { throw new exception("请求发生异常情况" . curl_strerror($error) ); } $curlInfo = curl_getinfo($curl); curl_close($curl); if ($curlInfo[http_code] == 200) { return true; }else{ throw new PrintException("文件上传打印机云端失败"); } }
下一篇:
项目上线后首次加载慢的解决方案