secret
Created

Zend File Transfer Adapter

  • Download Gist
gistfile1.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php
 
$adapter = new Http();
$tmpPath = 'data/tmp/';
$filename = $adapter->getFileName(null, false);
 
$adapter->setDestination($tmpPath)
->addValidator($extensionValidator)
->addValidator('Size', false, '10MB')
->addValidator('Count', false, 1, 1)
->addFilter('Rename', $tmpPath . uniqid());
 
if (!$adapter->receive()) {
return $this->error($adapter->getMessages());
}
 
$fileinfo = $adapter->getFileInfo();
$mimeType = $fileinfo['upfile']['type'];
$data = file_get_contents($fileinfo['upfile']['tmp_name']);
 
return $this->createAttachment(array(
'attachment' => array(
'filename' => $filename,
'mimetype' => $mimeType,
'data' => $data,
)
));

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.