简体   繁体   English

如何检查是否选择了文件 <input type=“file”> 在PHP中?

[英]How do I check if a file is selected for <input type=“file”> in PHP?

I want to check if the user has selected an image for upload. 我想检查用户是否选择了要上传的图像。 What is the php script to do that after the user has clicked submit... 用户单击提交后,php脚本的作用是什么?

I tried file_exist(), but that expects a string rather than an array and it seems that only works for an absolute path. 我尝试了file_exist(),但它期望使用字符串而不是数组,并且似乎仅适用于绝对路径。 Since I don't know which folder the user is going to upload from, this doesn't work. 由于我不知道用户要从哪个文件夹上载,因此无法使用。

Can someone help? 有人可以帮忙吗?

Take a look at the $_FILES superglobal . 看一下$_FILES superglobal

Tizag Tutorial: http://www.tizag.com/phpT/fileupload.php Tizag教程: http ://www.tizag.com/phpT/fileupload.php

If you do a print_r($_FILES) , you will see everything you need. 如果执行print_r($_FILES) ,您将看到所需的一切。

You need to use the super global variable $_FILES . 您需要使用超级全局变量$_FILES

More info . 更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM