概述
<template>
<div>
<form action="/file/upload" method="post" enctype="multipart/form-data">
<label for="file">文件名:</label>
<input type="file" name="up_file" @change="getFile($event)" />
<br />
<input type="submit" name="submit" value="上传文件" />
</form>
</div>
</template>
<script>
// import http from '@/assets/http.js'
export default {
name: 'Home',
data () {
return {
file: ''
}
},
methods: {
getFile (event) {
this.file = event.target.files[0]
console.log(this.file)
}
}
}
</script>
<style scoped>
</style>
后端:
// if (file_exists("/User/xx/" . $_FILES["file"]["name"])) {
// echo " 文件已经存在。 ";
// } else {
// move_uploaded_file($_FILES["up_file"]["tmp_name"], "/home/homework/xiaoxiao/" . $_FILES["up_file"]["name"]);
// echo "文件存储在: " . "/home/homework/xx/" . $_FILES["up_file"]["name"];
// }
$allowed = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES[Service_Page_File_UploadToCos::UPLOAD_FILE_ID]["name"]);
$extension = end($temp); // 获取文件后缀名
if ((($_FILES[Service_Page_File_UploadToCos::UPLOAD_FILE_ID]["type"] == "image/gif")
|| ($_FILES[Service_Page_File_UploadToCos::UPLOAD_FILE_ID]["type"] == "image/jpeg")
|| ($_FILES[Service_Page_File_UploadToCos::UPLOAD_FILE_ID]["type"] == "image/jpg")
|| ($_FILES[Service_Page_File_UploadToCos::UPLOAD_FILE_ID]["type"] == "image/pjpeg")
|| ($_FILES[Service_Page_File_UploadToCos::UPLOAD_FILE_ID]["type"] == "image/x-png")
|| ($_FILES[Service_Page_File_UploadToCos::UPLOAD_FILE_ID]["type"] == "image/png"))
&& in_array($extension, $allowed)) {
$uploadObj = new Service_Upload();
$arrOutput = $uploadObj->execute();
} else {
throw new Exception(
ExceptionCodes::PARAM_ERROR,
"只能上传图片");
}
最后
以上就是开心寒风为你收集整理的vue 上传附件的全部内容,希望文章能够帮你解决vue 上传附件所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复