【问题标题】:php-form-builder-class files not being uploadedphp-form-b​​uilder-class 文件未上传
【发布时间】:2013-02-01 21:40:48
【问题描述】:

我试图让 File 元素在 pfbc 中工作,但除了 $_POST['AvatarLrg'] 中的文件名之外,我没有得到任何东西,$_FILES 为空。有人有我可以细读的工作示例吗?

在顶部:

<?php
$form = new Form('trucking_edit');
$form->configure(array( "enctype" => "multipart/form-data" ));
$form->addElement(new Element_File("Profile Avatar:", "AvatarLrg"));
$form->addElement(new Element_Button);
?>

在体内:

<?php $form->render(); ?>

表单显示正常,所有其他元素都能正常显示和工作,只有文件元素:/ 任何帮助表示赞赏。

编辑:生成的 HTML:

<form method="POST" id="edit_profile" action="profile.php?pid=16&edit=save" name="tf_profileedit">
...
<div class="control-group">
   <label class="control-label" for="trucking_edit-element-3">Profile Avatar:</label>
   <div class="controls">
      <input type="file" name="AvatarLrg" id="trucking_edit-element-3"/>
   </div>
</div>
...
</form>

【问题讨论】:

  • 可以添加表单生成的HTML吗?

标签: php forms file-upload


【解决方案1】:

我从未使用过该类,但错误原因是表单标签中缺少 enctype 属性。

所以请检查代码中的$form-&gt;configure(array( "enctype" =&gt; "multipart/form-data" )); 行。

【讨论】:

    【解决方案2】:
    <form method="POST" enctype='multipart/form-data' id="edit_profile" action="profile.php?pid=16&edit=save" name="tf_profileedit">
    ...
    <div class="control-group">
       <label class="control-label" for="trucking_edit-element-3">Profile Avatar:</label>
       <div class="controls">
          <input type="file" name="AvatarLrg" id="trucking_edit-element-3"/>
       </div>
    </div>
    ...
    </form>
    

    你忘记了编码类型

    【讨论】:

      【解决方案3】:

      我发现了问题;页面上的另一个表单正在干扰它(由于旧代码它们重叠)。我删除了另一种形式,它可以工作。我还可以删除 enctype 行,因为当您添加文件元素时 PBFC 会自动更改 enctype。谢谢大家帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-02-13
        • 2021-03-05
        • 2021-08-03
        • 2011-02-12
        • 1970-01-01
        • 2012-06-04
        • 1970-01-01
        • 2021-03-26
        相关资源
        最近更新 更多