【问题标题】:Can't upload files larger than 97.66 KB in Yii2 Framework with Kartik's FileInput widget无法使用 Kartik 的 FileInput 小部件在 Yii2 框架中上传大于 97.66 KB 的文件
【发布时间】:2018-11-10 15:23:36
【问题描述】:

当我尝试上传大于 97.66 KB 的文件时,我收到此错误(翻译自西班牙语):

“文件太大。它的大小不能超过 97.66 Kib。”

这是我的小部件设置:

Modal::begin([
            //'title'=>'File Input inside Modal',
            'header' => 'Agregar foto',
            'toggleButton' => [
                'label'=>'Agregar foto',
                'class'=>'btn btn-default',
                //'href' => Url::to(['afiliado/foto']),
                'value' => Url::to('index.php?r=afiliado/foto&id=' . $model->id),
            ],
        ]);
        echo $form->field($model, 'image')->widget(FileInput::classname(), [
            'options' => ['accept' => 'image/*'],
            'pluginOptions'=>[
                'maxFileCount' => 1,
                'allowedFileExtensions'=>['jpg','jpeg','gif','png'],
                'showUpload' => false,
                'maxImageWidth' => 2400,
                'maxImageHeight' => 2400,
                'resizeImage' => true,
                'maxFilePreviewSize' => 10240,
                'minImageWidth' => 50,
                'minImageHeight'=> 50,
                'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
                'maxFileSize' => 1024
            ],
        ]);
        Modal::end();

在我的 php.ini 中,我设置了:

upload_max_filesize = 99MB
post_max_size = 100MB

提前致谢。

【问题讨论】:

  • 您的型号代码在哪里,您需要在您的问题中为image 字段添加rules() 设置
  • @MuhammadOmerAslam 这就是问题所在!我还必须更改设置为 100000 的 rules() 方法。谢谢!

标签: php file-upload yii2


【解决方案1】:

您需要使用UploadedFile::getInstance('image') 获取文件,并将模型规则更改为在1024 * 1024 * 100 周围使用maxSize 以在100MB 周围设置限制

[['image'],
   'file',
   'skipOnEmpty' => false,
   'extensions' => 'jpg, png, gif, jpeg',
   'maxSize' => 1024 * 1024 * 100,
   'tooBig' => 'The file was larger than 100MB. Please upload a smaller file.',
],

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多