Skip to content

Instantly share code, notes, and snippets.

@cgmartin
Forked from jordiwes/gist:4667235
Last active December 11, 2015 22:09
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 cgmartin/4667932 to your computer and use it in GitHub Desktop.
Save cgmartin/4667932 to your computer and use it in GitHub Desktop.
<h1>Transfer Test</h1>
<?php if (!is_null($this->success)) { ?>
<h2>
<?php echo ($this->success) ? 'Upload successful!' : 'unsuccessful.'; ?>
</h2>
<?php } ?>
<form method="POST" enctype="multipart/form-data">
File to upload: <input type="file" name="upfile"><br>
<input type="submit" value="Submit">
</form>
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\File\Transfer\Adapter\Http;
use Zend\Debug\Debug;
class TransferController extends AbstractActionController
{
public function indexAction()
{
$adapter = new Http();
//$size = new Size(array('min'=>2000)); //minimum bytes filesize
//$adapter->setValidators(array($size), $File['name']);
/*if (!$adapter->isValid()){
$dataError = $adapter->getMessages();
$error = array();
foreach($dataError as $key=>$row) {
$error[] = $row;
}
} else {
*/
$rtn = array('success' => null);
if ($this->getRequest()->isPost()) {
$upfile = $_FILES['upfile'];
$adapter->setDestination('./data/uploads/');
$rtn['success'] = $adapter->receive($upfile['name']);
}
return new ViewModel($rtn);
}
public function transferAction()
{
$upload = new \Zend\File\Transfer\Transfer();
$upload->setDestination('./data/uploads/');
$rtn = array('success' => null);
if ($this->getRequest()->isPost()) {
$files = $upload->getFileInfo();
foreach ($files as $file => $info) {
if (!$upload->isUploaded($file)) {
print "<h3>Not Uploaded</h3>";
Debug::dump($file);
continue;
}
if (!$upload->isValid($file)) {
print "<h4>Not Valid</h4>";
Debug::dump($file);
continue;
}
}
$rtn['success'] = $upload->receive();
}
return new ViewModel($rtn);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment