大家都使用過curl進行檔案上傳 ,我最近做到這個功能,既然遇到了,所以拿出來跟大家分享,大神請無視。
以php5.5為分界線
5.5以下的我們使用老方式
$post
= array('name'
=>
'file'
, 'file'
=>
'@'
. $html_file);
$post['dir'] =
'c'.
$id;
$post['type'] =
$type
;$ch
= curl_init
();curl_setopt
($ch
, curlopt_header
, false);
//這個相容低版本的php
curl_setopt
($ch
, curlopt_safe_upload
, false);
curl_setopt
($ch
, curlopt_post
, true);
curl_setopt
($ch
, curlopt_returntransfer
, true);
curl_setopt
($ch
,curlopt_binarytransfer
,true);
curl_setopt
($ch
, curlopt_postfields
,$post);
curl_setopt
($ch
, curlopt_url
, "");
//上傳類
$info
= curl_exec
($ch);
$result
= json_decode
($info
,true);
curl_close
($ch);
5.5以上 ,我們採用的是下面
這樣就ok了。
關於curl上傳檔案
在localhost根目錄建立1.php如下 localhost 8888是fiddler的 設定此選項用於讓fiddler抓獲post的請求 curl setopt ch,curlopt proxy,localhost 8888 下面這一句必須注釋,不然fiddler抓不到post的http請求 ...
PHP使用CURL上傳檔案
用curl上傳檔案的話很方便,什麼header,post串都不用生成了,用fsockopen要寫一堆 curl file array upimg e png.png 檔案路徑,前面要加 表明是檔案上傳.poststr boundary.r n 邊界開始,注意預設比header定義的boundary多...
curl 上傳檔案 GET POST
1 json格式 3 如果使用了 f引數,curl會以multipart form data的方式傳送post請求。f以key value的形式指定要上傳的引數,如果是檔案,則需要使用key file的形式。4 如 curl i k x get 02 42 06 如果直接傳送,會被系統解析。空格也會...