PHP完全自学手册(珍藏版) 中文pdf扫描版下载
- <?php
- $url = 'http://www.kuitao8.com/qrs/upload';
- $fname = realpath('21.png');
- if (!class_exists('CURLFile')) {
- $post = array('file' => '@' . $fname);
- }
- else {
- $cfile = new CURLFile($fname);
- $post = array(
- 'file' => $cfile,
- );
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
- curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: multipart/form-data'));
- curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
- curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 100);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
- curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
- $result = curl_exec ($ch);
- if ($result === FALSE) {
- echo "Error sending" . $fname . " " . curl_error($ch);
- curl_close ($ch);
- }else{
- curl_close ($ch);
- echo $result;
- }
- ?>
转载请注明:谷谷点程序 » php curl上传图片 兼容php5.6的版本