Home>Article>Web Front-end> How does vue+axios+php implement the file upload function?
Recommended: "PHP Video Tutorial"
When we are doing form submission, we often encounter some form submission requirements, then Will there be any different sparks after the axios of vue collides with the uploaded file? Listen to me one by one:
First of all, we need to write a form submission of axios of vue, because I use webpack, so code:
p input(type="file", ref="yin") button(@click="submit()") 点击上传
Use the pug template, you can also change it to HTML, it’s harmless. It mainly depends on the js logic code. First declare a FormData object, and then pass the value in post. At this time The url is a PHP file I use in wamp. The file is as follows:
0) { echo "错误:" . $file["error"]; } else { $name = iconv('utf-8', 'gb2312', "upload/" . $file["name"]); echo "文件名称:" . $file["name"] . ""; echo "文件类型:" . $file["type"] . ""; echo "文件大小:" . ($file["size"] / 1024) . "K"; echo "文件临时存储的位置:" . $file["tmp_name"] . ""; //保存上传的文件 if (file_exists("upload" . $file["name"])) { echo $file["name"] . "文件已经存在"; } else { //如果目录不存在则将该文件上传 if (move_uploaded_file($file['tmp_name'], $name)) { move_uploaded_file($file['tmp_name'], "upload/" . $file["name"]); } } }
Be sure to see the structure clearly, otherwise the uploaded file cannot be saved,
The header information in PHP solves the cross-domain problem and utf-8 transcoding solves the garbled problem, and then puts the obtained file into the upload folder;
is as follows:
Perfect
Related recommendations:
2020 Summary of front-end vue interview questions (with answers)
vue tutorial recommendation: 2020 latest 5 vue.js video tutorial selections
For more programming-related knowledge, please visit:Programming Teaching! !
The above is the detailed content of How does vue+axios+php implement the file upload function?. For more information, please follow other related articles on the PHP Chinese website!