我是靠谱客的博主 开心寒风,这篇文章主要介绍vue 上传附件,现在分享给大家,希望可以做个参考。

 

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<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>

后端:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// 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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部