Created
February 20, 2013 16:51
-
-
Save cgmartin/4997016 to your computer and use it in GitHub Desktop.
Zend\Transfer functional test
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\Debug\Debug; | |
class IndexController extends AbstractActionController | |
{ | |
public function indexAction() | |
{ | |
return new ViewModel(); | |
} | |
public function transferAction() | |
{ | |
$upload = new \Zend\File\Transfer\Transfer(); | |
$upload->setDestination('./data/tmpuploads/'); | |
$upload->addValidator('Extension', false, array('extension' => array('jpg','jpeg','png'))); | |
$upload->addValidator('Count', false, array('max' => 1)); | |
$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; | |
} | |
} | |
if ($upload->hasErrors()) { | |
$errors = $upload->getMessages(); | |
Debug::dump($errors); | |
} | |
$rtn['success'] = $upload->receive(); | |
} | |
return new ViewModel($rtn); | |
} | |
} |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment