Php 在zend framework 2中重命名上载文件

Php 在zend framework 2中重命名上载文件,php,zend-framework,zend-framework2,Php,Zend Framework,Zend Framework2,您能告诉我如何在上传前更改文件名吗?在调用receive方法之前,请执行以下操作: $request = $this->getRequest(); if($request->isPost()) { $files = $request->getFiles()->toArray(); $httpadapter = new Http(); $filesize = new Size(array('max' => 1

您能告诉我如何在上传前更改文件名吗?在调用receive方法之前,请执行以下操作:

   $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(); 
         }
     }
}

希望能有所帮助

你能举个简单的例子吗显然,当“php”脚本获取文件时,你必须处理“用户提供的文件名”的相关信息。但是,您不必使用提供的名称来命名上载的文件。您必须将上载的文件链接到提供的名称。有很多方法可以做到这一点。将提供的文件名编码为base64编码,并将其用作文件名(带有用户id),然后创建一个数据库条目,并将其作为密钥。注意:base64编码始终可以安全使用
$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);
}