简体   繁体   English

Cakephp Upload插件允许尽管验证规则也上传任何文件扩展名

[英]Cakephp Upload plugin allows any file extension to be uploaded despite validation rules

'model' => array(
        'rule' => array('isValidExtension', array('xls')),
        'message' => 'File does not have a stl extension'
        ),

Allows absolutely any file to be uploaded. 绝对允许任何文件上传。 I have this is as my first validation rule. 我将这作为我的第一个验证规则。 Other validation rules like notEmpty, and isUnique work fine on the same form element. 其他验证规则(例如notEmpty和isUnique)可以在同一表单元素上正常工作。

Tried adding stl to the array found in the main behavior: 'extensions' => array('xls') - also did not work. 尝试将stl添加到在主要行为中找到的数组:'extensions'=> array('xls')-也不起作用。

Any idea on what I'm doing wrong here? 对我在这里做错的任何想法吗?

Also: This appears to happen regardless of the file extension I pick. 另外:无论我选择什么文件扩展名,这种情况似乎都会发生。 No matter what, it doesn't call the file invalid. 无论如何,它不会称该文件无效。 The same issue appears to happen with Mime types as well. 同样的问题似乎也发生在Mime类型上。

The plugin URL is: https://github.com/josegonzalez/upload EDIT: Upon further investigation of UploadBehavior.php, and some debugging it doesn't seem like any of the custom validaiton rules are being loaded. 插件URL为: https : //github.com/josegonzalez/upload编辑:在对UploadBehavior.php进行了进一步调查之后,并进行了一些调试,似乎未加载任何自定义有效规则。 I wonder why this could be? 我不知道为什么会这样?

Have you tried going through the plugin code while your upload is in progress? 上传过程中,您是否尝试过插件代码? The validation function is located in 验证功能位于

Model/Behavior/UploadBehavior.php line 746

I suggest you put a couple of pr() and die() statements to see what the value of the $check and $extensions variables are. 我建议您放置几个pr()和die()语句,以查看$ check和$ extensions变量的值是什么。

Don't forget to remove those after! 不要忘记将其删除!

Diagnosed the problem and fixed: 诊断问题并修复:

I had bad syntax in my model validations. 我在模型验证中语法错误。

I had several of the same in a row like: 我连续有几个相同的东西:

'model'=> array(
       'rule' => 'rule',
       'message' => 'message'
 ),
 'model'=> array(
       'rule' => 'rule',
       'message' => 'message'
 ),
 'model'=> array(
       'rule' => 'rule',
       'message' => 'message'
 )

Seems this was the cause of the problem. 看来这是问题的原因。 Substituting 替代

'model' => array(
   'rulename' => array(
                'rule' => array('rule'),
                'message' => 'message'
                ),

    'rulename' => array(
                'rule' => array('rule'),
                'message' => 'message'
                ),

    'rulename' => array(
                'rule' => array('rule'),
                'message' => 'message'
                )
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM