【发布时间】:2013-03-24 18:57:20
【问题描述】:
我参考http://samsonasik.wordpress.com/2012/08/31/zend-framework-2-creating-upload-form-file-validation/,按照这个,我可以通过ZF2中的重命名过滤器成功上传1个文件。
但是,当我使用这种方式上传 2 个文件时,它就出错了。我将我的代码粘贴如下:
$this->add(array(
'name' => 'bigpicture',
'attributes' => array(
'type' => 'file'
),
'options' => array(
'label' => 'Big Pic'
)
));
$this->add(array(
'name' => 'smallpicture',
'attributes' => array(
'type' => 'file'
),
'options' => array(
'label' => 'Small Pic'
)
));
<div class="row"><?php echo $this->formRow($form->get('smallpicture')) ?></div>
<div class="row"><?php echo $this->formRow($form->get('bigpicture')) ?></div>
$data = array_merge(
$request->getPost()->toArray(),
$request->getFiles()->toArray()
);
$form->setData($data);
if ($form->isValid()) {
$product->exchangeArray($form->getData());
$picid = $this->getProductTable()->saveProduct($product);
$pathstr = $this->md5path($picid);
$this->folder('public/images/product/'.$pathstr);
//move_uploaded_file($data['smallpicture']['tmp_name'], 'public/images/product/'.$pathstr.'/'.$picid.'_small.jpg');
//move_uploaded_file($data['bigpicture']['tmp_name'], 'public/images/product/'.$pathstr.'/'.$picid.'_big.jpg');
$fileadaptersmall = new \Zend\File\Transfer\Adapter\Http();
$fileadaptersmall->addFilter('File\Rename',array(
'source' => $data['smallpicture']['tmp_name'],
'target' => 'public/images/product/'.$pathstr.'/'.$picid.'_small.jpg',
'overwrite' => true
));
$fileadaptersmall->receive();
$fileadapterbig = new \Zend\File\Transfer\Adapter\Http();
$fileadapterbig->addFilter('File\Rename',array(
'source' => $data['bigpicture']['tmp_name'],
'target' => 'public/images/product/'.$pathstr.'/'.$picid.'_big.jpg',
'overwrite' => true
));
$fileadapterbig->receive();
}
以上是形式,视图,动作。 使用这种方式,只有小图上传成功。大局出了问题。 警告闪烁如下:
警告:move_uploaded_file(C:\WINDOWS\TMP\small.jpg):无法打开流:无效参数 E:\myproject\vendor\zendframework\zendframework\library\zend\file\transfer\adapter\http.php 在第 173 行
警告:move_uploaded_file():无法移动 'C:\WINDOWS\TMP\php76.tmp' 到 'C:\WINDOWS\TEMP\big.jpg' 中 E:\myproject\vendor\zendframework\zendframework\library\zend\file\transfer\adapter\http.php 在第 173 行
谁能告诉我如何以这种方式上传多个文件。你知道的,重命名过滤方式和上面类似。谢谢。
【问题讨论】:
标签: php file-upload file-io zend-framework2