我需要上传多个文件,我正在使用materializecss ,它使您可以选择在一个输入中上传多个文件:
<div class="row">
<form class="col s12">
<div class="file-field input-field">
<div class="btn">
<span>Browse</span>
<input type="file" multiple>
</div>
<div class="file-path-wrapper">
<input type="text" name="pictures" class="file-path validate" type="text" placeholder="Upload multiple files">
</div>
</div>
</form>
</div>
materialize.js 对此执行以下操作:
$(document).on('change', '.file-field input[type="file"]', function () {
var file_field = $(this).closest('.file-field');
var path_input = file_field.find('input.file-path');
var files = $(this)[0].files;
var file_names = [];
for (var i = 0; i < files.length; i++) {
file_names.push(files[i].name);
}
path_input.val(file_names.join(", "));
path_input.trigger('change');
});
所以,通过$_POST
我只能获取我想要上传的文件的名称。我需要文件的完整路径才能将它们上传到我的服务器中。
我将不胜感激任何帮助。
最佳答案
你无法获取这些路径;这会侵犯用户的隐私。
文件 API 规范对 name
属性有这样的规定(重点是我的):
The name of the file; on getting, this must return the name of the file as a string. There are numerous file name variations and conventions used by different underlying OS file systems; this is merely the name of the file, without path information.
关于php - 多个文件输入实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41810699/