php - 在一组上传的文件上应用 php 代码
问题描述
我有一个 php 代码,可以从用户上传的 .dat 文件中提取一些信息。现在我想对一组上传的文件应用这种处理。所以用户可以在点击上传时选择一组文件,必须对每个文件进行处理。我已经尝试过了,但它不起作用:
<form method="post" enctype="multipart/form-data">
<label>Selectionner le fichier .dat</label>
<input type="file" name="excel" />
<br />
<input type="submit" name="import" class="btn btn-info" value="Import" />
</form>
先感谢您。
解决方案
要让用户选择多个文件,您必须使用该multiple
属性并将括号添加[]
到输入名称。
你可以这样做:
<form method="post" enctype="multipart/form-data">
<label>Selectionner le fichier .dat</label>
<input type="file" name="excel[]" multiple />
<br />
<input type="submit" name="import" class="btn btn-info" value="Import" />
</form>
然后你可以解析$_FILES
数组,你会发现所有上传的文件,例如:
Array
(
[excel] => Array
(
[name] => Array
(
[0] => img1.PNG
[1] => img2.PNG
[2] => img3.jpg
[3] => img4.png
)
[type] => Array
(
[0] => image/png
[1] => image/png
[2] => image/jpeg
[3] => image/png
)
[tmp_name] => Array
(
[0] => /tmp/phpWh5NRz
[1] => /tmp/php6KEOer
[2] => /tmp/phprLvUBi
[3] => /tmp/phplTP0Y9
)
[error] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
[size] => Array
(
[0] => 63515
[1] => 54484
[2] => 14001
[3] => 84938
)
)
)
推荐阅读
- vue.js - 从 index.js 访问时,本地存储值变为空
- spring-security - spring-security 5.2 中缺少依赖项 org.bouncycastle
- java - 我希望我的变量 value3 使用循环添加 5 十次。但它只添加一次。如何解决这个问题?
- android - Flutter for iOS 和 Android 中的视频播放功能,我们可以隐藏进度条和跳过功能
- kotlin - 科特林。尝试使用具体类型来解析列表和数组
- php - 如何在 PHP 中设置写入慢速文件系统的超时?
- angular - 使用 ngx-bootstrap typeahead 的自定义 ag-grid 角度单元格编辑组件无法正确显示
- angular - 当我选择要添加的其他人时,Angular Keep 文件
- arrays - 如果目标词不存在,则汇总数据框并插入 0 进行排序
- add - UPS Request Access Key failed with You are not allowed to add this account type to your profile