$request = $this->getRequest();
if($request->isPost()) {
$files = $request->getFiles()->toArray();
$httpadapter = new Http();
$filesize = new Size(array('max' => 100000 )); //100KB
$extension = new Extension(array('extension' => array('doc')));
$httpadapter->setValidators(array($filesize, $extension), $files['resume']['name']);
if($httpadapter->isValid()) {
$httpadapter->setDestination('./data/upload/');
if($httpadapter->receive($files['resume']['name'])) {
$newfile = $httpadapter->getFileName();
}
}
}
您能否告诉我如何在上传
之前更改文件名答案 0 :(得分:2)
在调用receive方法之前执行类似的操作:
$destination = './uploads/picture';
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
$newName = md5(rand(). $file['name']) . '.' . $ext;
$adapter->addFilter('File\Rename', array(
'target' => $destination . '/' . $newName,
));
if ($adapter->receive($info['name'])) {
$file = $adapter->getFilter('File\Rename')->getFile();
$target = $file[0]['target'];
var_dump($target);
}
希望有所帮助