gpt4 book ai didi

php - 当大小大于最大大小时,文件上传 + 哈希给我一个问题

转载 作者:搜寻专家 更新时间:2023-10-31 20:53:50 24 4
gpt4 key购买 nike

我注意到一些奇怪的事情,想知道是否有人可以在他们这边测试我的代码,如果他们得到同样的结果,请告诉我。

我有一个非常简单的表单(请参阅下面的完整表单代码和操作代码),它只有一个文件上传 + 隐藏哈希 + 提交按钮。文件上传的最大大小限制设置为 10000000(约 9.5MB)。

当我尝试上传一个大于限制的文件时,表单不应该被验证,但我在哈希 token 本身中得到一个错误 Value is required and can't be empty .有人可以确认吗?看起来 token 正在被清除。我猜这可能发生在重定向或其他情况下,但我没有进行任何重定向,除非在后台发生了我没有注意到的事情。

这是表单代码和我的操作代码

class Application_Form_TestForm extends Zend_Form
{

public function init()
{

$file = new Zend_Form_Element_File('file');
$file->setDestination(APPLICATION_PATH);
$file->addValidator('Size', false, 10000000);
$file->setMaxFileSize(10000000);
$this->addElement($file);

$hash = new Zend_Form_Element_Hash('hash');
$hash->setIgnore(true)
->setSalt('mysalt');
$this->addElement($hash);

$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Test')
->setIgnore(true);
$this->addElement($submit);

$this->setAttrib('enctype', 'multipart/form-data');
$this->setMethod('post');
}
}

在我的 Controller 中,我进行通常的验证

public function indexAction()
{
$form = new Application_Form_TestForm();
$this->view->form = $form;

if($this->_request->isPost()){
echo "post";
if($form->isValid($this->_request->getPost())){
echo " valid";
}
}

}

最佳答案

这似乎与您在 php.ini 中的 post_max_size 或 upload_max_filesize 值有关。例如,post_max_size 的默认值为 8M,小于您的最大文件大小。

关于php - 当大小大于最大大小时,文件上传 + 哈希给我一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4789412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com