【问题标题】:Zend Framework - Zend_File_Transfer Upload HandlerZend 框架 - Zend_File_Transfer 上传处理程序
【发布时间】:2012-03-12 19:04:35
【问题描述】:

在 Zend 中使用类似的东西时:

$upload = new Zend_File_Transfer_Adapter_Http();
$upload->setDestination('/some/directory');
$upload->addValidator(x)
->addValidator(y);
$upload->receive();

上传的文件是先上传到 tmp 目录,验证然后移动到 'some/directory' 还是直接保存到 setDestination 目录?如果是前者,在我看来这与“move_uploaded_file”在上传到 tmp 目录后的作用相同。

ZF 是否提供某种类型的 http 流处理程序来将文件本地写入特定目录?即类似于 nodejs 或 django 的东西?

【问题讨论】:

    标签: php zend-framework zend-file


    【解决方案1】:

    Zend_File_Transfer_Adapter_Http 在您指定的验证者验证后使用move_uploaded_file

    here:

    public function receive($files = null)
    {
        if (!$this->isValid($files)) {
            return false;
        }
        ... some code ...
    
        if (!move_uploaded_file($content['tmp_name'], $filename)) {
            if ($content['options']['ignoreNoFile']) {
                $this->_files[$file]['received'] = true;
                $this->_files[$file]['filtered'] = true;
                continue;
            }
    
            $this->_files[$file]['received'] = false;
            return false;
        }
    

    没有特殊的机制,它只是标准函数的包装

    对于直接上传到您的目录,您可以使用类似

    $input = fopen("php://input", "r");
    $file = fopen("/my/directory/filename.eee", "w");
    while ($data = fread($input, 1024)){
        fwrite($file, $data);
    }
    

    但在 ZF 中似乎不是这样的

    【讨论】:

    • 我想这可能也有一些包装器,但我想现在是普通的好 ol' PHP。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 2011-10-13
    • 2011-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多