我正在尝试将简历从用户上传到我的网站。
所以我已经将文件上传到doc,pdf和docx。
文件上传系统如下图
上传后,当用户点击重命名的文件名(下面的“选择文件”按钮)时,将下载新上传的文件。
PDF工作得很好。 doc和docx文件上传成功,但下载后无法打开。
这是来自cvAction文件的代码片段: -
$request = $this->getRequest();
if ($request->isPost()) {
$post_data = $request->getPost();
$nonFile = $request->getPost()->toArray();
$File = $this->params()->fromFiles('attachment');
if ($File['name'] != "") {
$post_data = array_merge($nonFile, array('attachment' => $File['name']));
$size = new Size(array('max' => '1MB')); //minimum bytes filesize
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->setValidators(array($size), $File['name']);
$extensionvalidator = new \Zend\Validator\File\Extension(array('extension' => array('pdf', 'doc', 'docx')));
$adapter->setValidators(array($extensionvalidator), $File['name']);
if (!$adapter->isValid()) {
$dataError = $adapter->getMessages();
$error = array();
foreach ($dataError as $key => $row)
$message .= $row;
// $form->setMessages(array('fileupload' => $error));
$is_validation_error = 1;
} else {
//$adapter->setDestination(dirname(__DIR__) . '/assets');
$adapter->setDestination('public/upload/cv');
$extension = pathinfo($File['name'], PATHINFO_EXTENSION);
$new_file_name = strtolower($full_name) . "_" . date('dmyHis') . '.' . $extension;
$adapter->addFilter('File\Rename', array(
'target' => $adapter->getDestination() . '/' . $new_file_name,
'overwrite' => true
));
$adapter->receive($File['name']);
/*
if ($adapter->receive($File['name'])) {
}
*/
}
} else {
$new_file_name = $cv_check["upload_cv"];
}
plz帮助解决问题。提前谢谢