gpt4 book ai didi

php - 如何在 Zend Framework 2 和 Zend Filter 中以 Zip 格式压缩上传的文件

转载 作者:搜寻专家 更新时间:2023-10-31 22:04:13 25 4
gpt4 key购买 nike

如何使用 \Zend\File\Transfer\Adapter\Http()\Zend\Filter\Compress() 上传文件并压缩它?

这是我已经写的:

public function UploadprocessAction()
{
$this->layout('layout/myaccount');

// Get the identity information
$Identity = $this->zfcUserAuthentication()->getIdentity();
$userId = $Identity->getId();

// Get the TableGateway object to retrieve the data
$user = $this->getServiceLocator()->get('PdTable');

// Get the user
$myUser = $user->getPdByUserId($userId);

$form = $this->getServiceLocator()->get('FormElementManager')->get('Cv\Form\UploadForm');

$request = $this->getRequest();

if ($request->isPost()) {
$upload = new Uploads();
$uploadFile = $this->params()->fromFiles('fileupload');
$uploadPath = $this->getFileUploadLocation();

$form->setData($request->getPost());

if ($form->isValid()) {

$codedfile = strtolower($myUser->getPac() . "_" . $this->CreateCode()) . ".zip";

// Fetch Configuration from Module Config
$uploadPath = $this->getFileUploadLocation();

// Save Uploaded file
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->setDestination($uploadPath);

// Do not allow files with extension php or exe
$adapter->addValidator('ExcludeExtension', false, 'php,exe');

// Adds a filter to lowercase the uploaded textfile
$adapter->addFilter('LowerCase');

$filter = new Compress(array(
'adapter' => 'Zip',
'options' => array (
'target' => $uploadPath . "/" .$codedfile,
'archive' => $codedfile
)
));

$adapter->addFilter($filter);

if ($adapter->receive()) {

$exchange_data = array();
$exchange_data['title'] = $request->getPost()->get('title');
$exchange_data['originalfilename'] = $uploadFile['name'];
$exchange_data['codedfilename'] = $codedfile;
$exchange_data['mimetype'] = $uploadFile['type'];
$exchange_data['size'] = $uploadFile['size'];
$exchange_data['idpersonaldata'] = $myUser->id;

$upload->exchangeArray($exchange_data);

$uploadTable = $this->getServiceLocator()->get('UploadsTable');
$uploadTable->saveUpload($upload);

}

return $this->redirect()->toRoute('cv/uploads' , array(
'action' => 'index'
));
}
}

$viewModel = new ViewModel(array (
'error' => true,
'form' => $form
));
$viewModel->setTemplate('cv/uploads/upload');
return $viewModel;

}

但是在这种方式下,它上传的文件没有任何压缩。我的代码有什么问题?

最佳答案

您必须先接收文件,然后才能调用压缩过滤器。

关于php - 如何在 Zend Framework 2 和 Zend Filter 中以 Zip 格式压缩上传的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21981744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com