2011-12-18 70 views
1

我嘗試如何通過kohana 3中的cURL上傳文件?

$request = Request::factory($url)->method(Request::POST)->post('xml', '@' . $filepath); 
echo $request->execute(); 

但的print_r($ _ FILES);在目標腳本中返回空數組。 Kohana中的

版本是3.2.0穩定

我要的是一個簡單的模擬

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0"); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml' => '@' . $filepath)); 
$res = curl_exec($ch); 
echo $res; 

回答

0

嘗試:

 
$request_url = 'your_url_here'; 
     $post_params['name'] = urlencode('Test User'); 
     $post_params['file'] = ‘@’.'demo/testfile.txt’; 
     $post_params['submit'] = urlencode('submit'); 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $request_url); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_POST, true); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params); 
     $result = curl_exec($ch); 
     curl_close($ch); 
+0

它不是Kohana) – Argnist 2011-12-18 07:17:41

0

現在它可能是使用Kohana開發利用3.3做請求#files()方法。

編輯:實際上,它不是官方發佈的一部分,所以在3.4之前,你可能無法做到這一點。