file - 是否可以为 Zend 文件传输适配器设置名称、类型、大小?

标签 file zend-framework http adapter transfer

我想为 Zend_File_Transfer_Adapter_Http 对象手动设置 name, type, size ,可以吗?

最佳答案

当然。但是你的陈述有些困惑。我想你的意思是限制上传文件的类型和大小,因为否则你可以很容易地创建一个名为“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

关于file - 是否可以为 Zend 文件传输适配器设置名称、类型、大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6607780/

相关文章:

angular6 http 请求返回 isTrusted

java - ClassLoader.getResource 不断为现有资源返回 null

python - 比较两个文件并写入一个新文件但只输出几行?

php - 用于 mysql 查询的 Zend PHP 类变量保留

zend-framework - .htaccess 不工作

http - 将服务请求重定向到另一台服务器

web-services - "already exist"的状态码

Python:读取模式。加载到列表(使用 for 循环)并在单独的代码块中使用 read() 方法

python - For循环不能在同一个文件描述符上工作两次

php - Zend Framework 1 - 通过 ssh 隧道的远程数据库连接