php - 发布输入类型文件问题 未发布任何值

标签 php html

我有一个表单,我在其中发布不同的字段,并且除了输入文件类型之外,发布的每种类型的字段似乎都有效。

我正在使用 var_dump($_POST); 并且所有其他字段都在那里,但输入类型文件中没有任何字段。

我的表单部分如下所示:

<form enctype="multipart/form-data" id="ajax-form" action="index2.php" method="POST" data-ajax="true">

并且适用于其他一切。

输入类型文件中有什么不同吗?

<input type="text" id="myid" name="myid" value="" /> ..This posts value

<input id="theimage" name="theimage" type="file" /> .. does not post value

大家有什么想法吗?

最佳答案

文件存储在$_FILES中,而不是$_POST

http://php.net/manual/en/reserved.variables.files.php $_FILES 变量

http://www.php.net/manual/en/features.file-upload.php PHP 文件上传手册。

处理文件(不进行错误检查):

$ROOT = "/path/to/store/files";
foreach($_FILES as $file => $details)
{   // Move each file from its temp directory to $ROOT
    $temp = $details['tmp_name'];
    $target = $details['name'];
    move_uploaded_file($temp, $ROOT.'/'.$target);
}

另请参阅http://www.php.net/manual/en/function.move-uploaded-file.php了解更多示例。

关于php - 发布输入类型文件问题 未发布任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50118787/

相关文章:

javascript - Light Gallery youtubeThumbSize不起作用

php - 多对多和急切加载 laravel

php - 如何检查 .mo 文件的有效性?

javascript - 尝试不使用gif实现滑动进度条

php - 如何使用 JQuery AJAX 实现通用 CSRF token ?

php - Mysql查询WHERE Json value = this

php - 包含填充数据的多选列表

javascript - 在 javascript 中将选项对象添加到 2 个选择框

javascript - 根据用户输入弹出模态

php - 连接 MySQL 表,然后将结果过滤为列名