html - 如何检查没有文件通过表单上传到服务器?
问题描述
我有下一个表格:
<form action="/upload" enctype="multipart/form-data" method="POST">
<input name="example" type="file">
<input type="submit" value="Upload">
</form>
在服务器端,我看到上传了大小为零的文件:
-----------------------------23370864791729106148808009039
Content-Disposition: form-data; name="example"; filename=""
Content-Type: application/octet-stream
-----------------------------23370864791729106148808009039--
如何检查用户没有为此file
字段选择任何内容?
解决方案
提交后,您可以将此代码用于您的 php 文件:
if($_FILES['example']['tmp_name'] != null){
//Actions you needed
}
如果它返回 true,则表示该文件已被选中。
推荐阅读
- r - 在 Linux CentOS 7 上安装 R oligo 和 RCurl 包失败
- ios - 使用本机反应运行 iOS 模拟器设备时出现问题
- r - 在 Linux gcc -std=gnu99 上安装 R 包时出错
- c - 使用指针查找字符串的长度
- amazon-redshift - 如果数据库中的任何用户都可以查看模式层次结构,那么 Redshift 中的 GRANT USAGE ON SCHEMA 有什么意义
- html - 如何修复 Datatables css 不适用于 Datatables?
- python - Python TkInter:网格属性的最右列和最底行值?
- stripe-payments - PHP 脚本上的 Stripe Payment 集成问题
- jquery - 使用 jquery 使除一个 div 之外的整个主体不可点击
- android - SharedPrefrences 的实际作用