【问题标题】:File upload using JForm使用 JForm 上传文件
【发布时间】:2013-05-24 08:52:34
【问题描述】:

我正在尝试使用 Joomla 的 (JForm File Type) 表单上传照片。提交表单和文件后,数据库中的文件字段为空。这里缺少什么?

我的字段与 jdocs 中的字段相似:

<field name="myfilevalue" type="file" label="Enter some text" description="Choose an image from your computer with maximum 100KB" size="10" accept="image/*" />

【问题讨论】:

    标签: joomla joomla2.5 jform


    【解决方案1】:

    据我所知,您需要在模型prepareTable 函数中手动处理该字段。

    您可以使用以下方式访问该文件:

    $jinput = JFactory::getApplication()->input;
    $files  = $jinput->files->get('jform');
    $file   = $files['myfilevalue']
    

    $file 数组然后包含以下键:

    • 错误
    • 姓名
    • 尺寸
    • tmp_name
    • 类型

    您还需要将上传的文件实际移动到最终目的地。这可以使用JFile::upload() 来完成。

    还要确保您的表单设置了enctype="multipart/form-data",否则将无法正常工作。

    【讨论】:

    • 您必须手动处理该字段。这通常可以在模型中的 prepareTable 函数中完成。
    猜你喜欢
    • 2015-02-03
    • 2014-08-15
    • 1970-01-01
    • 2019-02-16
    • 2011-08-16
    • 2016-01-11
    • 2017-06-28
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多