【问题标题】:Is it possible to set name, type, size for Zend File Transfer Adapter?是否可以为 Zend File Transfer Adapter 设置名称、类型、大小?
【发布时间】:2011-07-07 08:27:43
【问题描述】:

我想手动为Zend_File_Transfer_Adapter_Http对象设置nametypesize,可以吗?

【问题讨论】:

  • 我不确定你的意思。这些参数应在开始传输的文件上传表单中设置。

标签: file zend-framework http adapter transfer


【解决方案1】:

当然。但你的说法有些混乱。我想你的意思是限制上传文件的类型和大小,否则你可以轻松地创建一个名为“sampleFile.ext”的文件,并用特定大小的空格填充内容,我看不到任何内容不过很有用。

从一个新对象开始:

$uploaded_file = new Zend_File_Transfer_Adapter_Http();

文件大小验证器:

// Set a file size with 20000 bytes
    $upload->addValidator('Size', false, 20000);

    // Set a file size with 20 bytes minimum and 20000 bytes maximum
    $upload->addValidator('Size', false, array('min' => 20, 'max' => 20000));

    // Set a file size with 20 bytes minimum and 20000 bytes maximum and
    // a file count in one step
    $upload->setValidators(array(
            'Size'  => array('min' => 20, 'max' => 20000),
            'Count' => array('min' => 1, 'max' => 3),
    ));

扩展验证器:

// Limit the extensions to jpg and png files
    $upload->addValidator('Extension', false, 'jpg,png');

    // Limit the extensions to jpg and png files but use array notation
    $upload->addValidator('Extension', false, array('jpg', 'png'));

    // Check case sensitive
    $upload->addValidator('Extension', false, array('mo', 'png', 'case' => true));
    if (!$upload->isValid('C:\temp\myfile.MO')) {
        print 'Not valid because MO and mo do not match with case sensitivity;';
    }

排除文件扩展名验证器:

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

    // Do not allow files with extension php or exe, but use array notation
    $upload->addValidator('ExcludeExtension', false, array('php', 'exe'));

    // Check in a case-sensitive fashion
    $upload->addValidator('ExcludeExtension',
            false,
            array('php', 'exe', 'case' => true));
    $upload->addValidator('ExcludeExtension',
            false,
            array('php', 'exe', 'case' => true));

要更改文件名,请使用过滤器:Zend_File_Transfer_Http How to set uploaded file name

文件验证器官方参考:http://framework.zend.com/manual/1.11/en/zend.file.transfer.validators.html#zend.file.transfer.validators.extension

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-06
    • 2012-01-02
    • 2019-10-13
    • 2011-10-07
    • 2011-08-05
    • 2017-04-30
    • 2019-08-03
    相关资源
    最近更新 更多