gpt4 book ai didi

php - Yii 文件上传 $_FILE 为空

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

我正在尝试通过表单将图像上传到我的模型。我正在使用 Yii 1.1

模型在数据库中不包含“图像”列,所以我在模型中创建了这样的属性

public $image;

我在规则中添加了以下内容

array('image', 'file', 'types'=>'jpg,gif,png', 'allowEmpty'=>true),

在 View 中,我向表单添加了 htmlOption array('enctype' => 'multipart/form-data'),而对于文件上传:

<th><?php echo $form->labelEx($model, 'image'); ?></th>
<td><?php echo $form->fileField($model, 'image');?></td>
<th><?php echo $form->error($model, 'image');'>'?></th>

我看到了上传图片的按钮,当我按下按钮时,我的 Controller 的 Action 被调用但是如果我创建一个日志来显示 $_POST 和/或 $_FILES 我得到这个:

从 $_FILES 中记录

2016/07/07 18:18:12 [info] [application] FILE : 

Array
(
)

我从 $_POST 收到的日志

[Puntointeres] => Array
(
[Name] => My Name
[Description] => What ever
......
[image] =>
)

有什么帮助吗?

最佳答案

可能是你忘记设置加密类型了:

<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>

另外你的字段不正确,应该是:

$form->field($model, 'image')->fileInput()

还要记住 Yii 不会在 $_POST 中发送图像的值。它通过 $_POST 发送它在使用 inputFile 时生成的隐藏字段。

关于php - Yii 文件上传 $_FILE 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38250643/

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