Rumah  >  Artikel  >  pembangunan bahagian belakang  >  上传文件 - php://input在表单POST是否无效?

上传文件 - php://input在表单POST是否无效?

WBOY
WBOYasal
2016-06-06 20:34:441000semak imbas

<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://input is not available with enctype="multipart/form-data".

大意:enctype="multipart/form-data" 的时候 php://input 是无效的。

哎。我以前也写php,但后来发现他是一个难接触到更深层次东西的语言。这不符合我的性格,所以我放弃了。php在io方面的能力。真的是。。。哎。

还是老老实实地用 file_upload 之类的函数吧。虽然很低效,但是又能怎么样呢?

祝你好运。

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn