【发布时间】:2021-06-27 06:51:39
【问题描述】:
<form method="POST" @submit.prevent="share" >
<div id="imgs">
Select Images: <input type="file" ref="file" name="file[]" multiple ></form>
share(){
var formData=new FormData();
for( var i = 0; i < this.$refs.file.files.length; i++ ){
let file = this.$refs.file.files[i];
formData.append('file[' + i + ']', file);
};
axios.post('http://localhost/11/upload_img.php',formData,{
headers:{'Content-Type':'multipart/form-data'}
}).then((res)=>{
console.log("sent");
});
}}}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.4/vue.js"></script>
<form method="POST" @submit.prevent="share" >
<div id="imgs">
Select Images: <input type="file" ref="file" name="file[]" multiple >
我像上面一样在 vue js 中发送文件 这是我的 PHP 代码$filename=$_FILES['file']['name'];
$files=$_FILES['file'];
回声($files);
我得到了这个错误
注意:未定义索引:第 6 行 C:\xampp\htdocs\11\upload_img.php 中的文件
【问题讨论】:
标签: php vue.js file axios multiple-file-upload