Heim  >  Artikel  >  Backend-Entwicklung  >  上传文件 - php://input在表单POST是否无效?

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

WBOY
WBOYOriginal
2016-06-06 20:34:441001Durchsuche

<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 之类的函数吧。虽然很低效,但是又能怎么样呢?

祝你好运。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn