-
-
Save cgmartin/4667932 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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