doubi7739 2010-11-13 12:50
浏览 96
已采纳

PHP中的多部分表单数据解析

Forgive my ignorance in this..

I think I understand that using:

extract($_REQUEST);

in a php file will convert html form inputs into a corresponding variable. For instance:

<input type="text"name="author"/>

becomes:

$author

Is that right?

However, I'm confused as to how to handle a multipart form. For instance one with 1 file (an image) and two text inputs. How do I extract this data and put it into variables?

  • 写回答

2条回答 默认 最新

  • dongzhi5846 2010-11-13 13:09
    关注

    Okay, after another reading, your undeerstanding of extract is right. But note that the author input will generally be available as $_REQUEST["author"] anyway. Generally avoid to extract them all.

    If you for example want the value to be reused as form input you can write:

    <input name="author" value="<?=htmlspecialchars($_REQUEST["author"])?>">
    

    If you want to have shortnames, if for example it's too many fields and it spares lots of typing, then I'd recommend using the optional parameters to extract():

    extract($_REQUEST, EXTR_PREFIX_ALL, "i_");
    

    This would generate a $i_author variable, and all other input fields with a $i_ prefix. This is believed to have less sideeffects with other (hyopthetical) local or global variables. Also you can use array_map("htmlspecialchars",$_REQUEST) for extraction, if that aids the processing.


    Multipart form data will fill up the $_FILES array additionally, which has a different structure. See PHP manual http://php.net/manual/en/features.file-upload.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错