2011-02-13 27 views
0

有沒有人有使用curl將文件發送到zend應用程序的例子。我試圖模擬客戶端發送文件到服務器場景。所以我嘗試了這兩種方式,但我沒有收到任何發佈數據。這是$ POST數據捲曲方式如何用curl或Zend_Http_Client發送文件()

$url = 'http://test.com/test'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, true); 
$post = array(
    'file' => '@file.jpg' 
); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
$response = curl_exec($ch); 
curl_close($ch); 
var_dump($response); 

我也試圖與一個Zend_Http_Client

$client = new Zend_Http_Client($url); 
$client->setFileUpload('file.jpg', 'image'); 
$response = $client->request(); 
var_dump($results); 

那我就接收端做接收文件?當我輸出$this->_request->getParams()時,我沒有收到任何東西。這應該是什麼樣子?

+0

你在尋找這種東西http://stackoverflow.com/questions/665334/file-upload-using-zend-framework-1-7-4? – akond 2011-02-13 22:03:46

回答

1

您需要使用Zend_File_Transfer_Adapter_Http收到關於客戶端文件:(:在這種情況下\ TEMP C)

$adapter = new Zend_File_Transfer_Adapter_Http(); 

$adapter->setDestination('C:\temp'); 

if (!$adapter->receive()) { 
    $messages = $adapter->getMessages(); 
    echo implode("\n", $messages); 
} 

你的文件將在目標目錄中複製。