Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2012 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/83f582c74d45174e0538 to your computer and use it in GitHub Desktop.
Save anonymous/83f582c74d45174e0538 to your computer and use it in GitHub Desktop.
Zend File Transfer Adapter
<?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,
)
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment