开发者

How do I send a file with curl or Zend_Http_Client()

Does anyone have an example of sending a file to a zend application using curl. I'm trying to simulate a client sending a file to a server scenario. So I tried these 2 ways, but I'm not getting any post data. This is the curl way with $post data

$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 );

I also tried this with Zend_Http_Client

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

What am I supposed to do on the receiver end to receive the file? I'm not getting anything when I output $this->_request->getP开发者_运维知识库arams(). What is this supposed to look like?


You need to use Zend_File_Transfer_Adapter_Http to receive the file on the client side :

$adapter = new Zend_File_Transfer_Adapter_Http(); 

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

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

Your file will be copied in the destination directory (c:\temp in this case).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜