<code><form action="http://localhost/post.php" method="POST" name='aform'>
<input type="file" name="myfile" id="myfile">
<input type="submit" value="提交">
</form>
</code>html页面中使用上面这段代码。在php中如此接收:
<code>$postdata = file_get_contents("php://input");
</code>一直获取到的只有文件名,获取不到文件。想问问php://input在表单POST是否无效?是否只能走AJAX的时候才能获取到?还是说需要其他配置?
<code><form action="http://localhost/post.php" method="POST" name='aform'>
<input type="file" name="myfile" id="myfile">
<input type="submit" value="提交">
</form>
</code>html页面中使用上面这段代码。在php中如此接收:
<code>$postdata = file_get_contents("php://input");
</code>一直获取到的只有文件名,获取不到文件。想问问php://input在表单POST是否无效?是否只能走AJAX的时候才能获取到?还是说需要其他配置?
php://input 可以接受所有 body 内容。
但是遗憾的是:enctype="multipart/form-data" 时 php://input 无效
参见官方文档
立即学习“PHP免费学习笔记(深入)”;
php://input is not available with enctype="multipart/form-data".
大意:enctype="multipart/form-data" 的时候 php://input 是无效的。
哎。我以前也写php,但后来发现他是一个难接触到更深层次东西的语言。这不符合我的性格,所以我放弃了。php在io方面的能力。真的是。。。哎。
还是老老实实地用 file_upload 之类的函数吧。虽然很低效,但是又能怎么样呢?
祝你好运。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号