是否可以设置 Zend File Transfer Adapter 的名称、类型、大小?

发布于 2024-11-18 21:14:43 字数 121 浏览 7 评论 0原文

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

I want to set name, type, size for the Zend_File_Transfer_Adapter_Http object manually, is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城花音 2024-11-25 21:14:43

绝对地。但你的说法有些混乱。我想你的意思是限制上传文件的类型和大小,因为否则你可以轻松地创建一个名为“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 如何设置上传的文件名

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

Absolutely. But there is some confusion in your statement. I suppose you mean to limit the type and size for an uploaded file, because otherwise you could just create a file easily with the name "sampleFile.ext", and fill content with spaces for specific size, I can't see that of anything useful though.

Start with a new object:

$uploaded_file = new Zend_File_Transfer_Adapter_Http();

File size validators:

// 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),
    ));

Extension validators:

// 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;';
    }

Exclude file extension validators:

// 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));

To change file name, please use filter: Zend_File_Transfer_Http How to set uploaded file name

Official reference for file validators: http://framework.zend.com/manual/1.11/en/zend.file.transfer.validators.html#zend.file.transfer.validators.extension

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文