在前面的https://mp.youkuaiyun.com/postedit/80586507,https://mp.youkuaiyun.com/postedit/80586917这两个博客中初步的了解样式以及如何往后台传输文件,这一篇就简单的写一下后台的获取,用的后台python+django,有兴趣的可以学一下。
在上一节中upload 上传文件,用的是formdata,通过ajax传递,当然这个表单提交也是可以的,在我们传递了文件后,那么后台怎么获取呢?大致的代码如下:
#python3.6 后台代码
def getFile(request):
file = request.Files.get("file") #所有form表单提交的文件
hh = request.POST.get("hh") #form表单里面的其他内容
flagCount = file.name.count(".") #file.name指文件的名 file.name.count(".") 计算.号出现的次数
endFix = file.name.split(".",flagCount)[flagCount] #获取文件的后缀
save_path = "D:\\hhh" #文件存放的路径
if os.path.exists(all_path) == False: #没有该文件夹时生成该文件夹
os.mkdir(all_path)
all_path = save_path + file.name
file_