首页 > 解决方案 > 我想使用 Zend 框架 2 在同一表单上的 2 个不同路径上上传 2 个文件

问题描述

我的代码如下。只有第二个文件(shareholder1)正在上传,第一个文件没有上传。问题出在 AddFilter..

$upload = new Zend_File_Transfer();
$company_name = $post['idcmpname'];
$douments_path = realpath('companydocuments');
$current_yr = date("Y");
$yr8 = 2018;
$company_name = str_replace(' ', '_', $company_name);
$path_memorandum = $douments_path . '/' . $company_name . '/' . 'memorandum' . '/' . $current_yr;

if (!is_dir($path_memorandum)) {
    mkdir($path_memorandum, 0777, true);
}

$path_shareholder1 = $douments_path . '/' . $company_name . '/' . 'shareholder/' . $yr8;
if (!is_dir($path_shareholder1)) {
    mkdir($path_shareholder1, 0777, true);

    $filename_memorandum = str_replace(' ', '_', $files['memorandum1']['name']);
    $tmpName = $files['memorandum1']['tmp_name'];

    $filename_shareholder1 = str_replace(' ', '_', $files['shareholders1']['name']);
    $tmpName = $files['shareholders1']['tmp_name'];

    $upload->addValidator('Size', false, array('max' => '10MB', 'bytestring' => false));
    $upload->addValidator('Extension', false, array('jpeg', 'jpg', 'png', 'pdf', 'txt', 'xls', 'xlsx', 'ppt', 'doc', 'docx', 'rtf'));

    if ($upload->isValid()) {
        $upload->addFilter('Rename', $douments_path . '/' . $company_name . '/' . 'memorandum' . '/' . $current_yr . '/' . $filename_memorandum, 'memorandum1')
            ->addFilter('Rename', $douments_path . '/' . $company_name . '/' . 'shareholder/' . $yr8 . '/' . $filename_shareholder1, 'shareholders1');
    }
}

问题出在 AddFilter 中。我是 ZF 的新手

标签: phpfile-uploadzend-frameworkzend-framework2

解决方案


推荐阅读