如何轻松上传文件到一个服务器使用JavaScript(傻瓜) [英] How to Upload files easily to a server using Javascript (for Dummies)

查看:109
本文介绍了如何轻松上传文件到一个服务器使用JavaScript(傻瓜)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绝对是编程新手。我选择了Django开始,我正在通过这样的教程和页面学习。
我想要做的是这样的:
我的根文件夹中有一个.txt文件,当我运行一个特定的网页时,我从该文件获取信息并显示一些内容。问题是我需要用户可以从他们的计算机上传一个.txt,并且这个文件替换了我的根文件夹中的文件。所以,它被称为例如data.txt和存储,并刷新页面(现在像F5),以便显示的信息从新文件中获取。
任何人都可以告诉我如何做到这一点,一步一步解释'傻瓜'?如果可能的话,我想只用JavaScript(而不是Python)来完成。我不需要多次上传,上传不需要AJAX或类似的东西,尽管我知道它更好。
非常感谢!

解决方案

首先,javascript无法从客户端计算机上传文件,否则我会能够把你发送到一个能够窃取你计算机上的所有文件的网站。第二,你需要上传一个文件是一个html格式,用户可以选择一个文件,然后提交表单,从而上传到您的服务器。然后需要一个服务器端的脚本来移动上传的文件到任何你想要的地方。

第三,你应该真正小心允许上传到你的服务器,因为这可以第四,因为你使用的django作为你的服务器端语言,你可能只是想要一个恶意软件的安装在你的服务器上,如果不正确的话谷歌使用Django上传文件。这里是关于如何做文件上传的django文档:

https://docs.djangoproject.com/zh/dev/topics/http/file-uploads/?from=olddocs


I am absolutely new to programming. I have chosen Django to start, and I am learning through tutorials and pages like this. What I am trying to do is this: I have a .txt file in my root folder, and when I run a particular web page, I take information from that file and display some stuff. The problem is that I need that the users can upload a .txt from their computers, and that this file replaces the file in my root folder. So, that it is called for example data.txt and stored, and that the page refreshes (like F5, for now) so that the information shown is taken from that new file. Can anybody tell me how to do this, explained step by step 'for Dummies'? If possible, I would like to do it just in JavaScript (not Python). I don't need multiple uploads, and it is not necessary that the upload involves AJAX or anything like that, despite I know that it is nicer. Thank you very much!

解决方案

first, javascript cannot upload a file from the client's computer, otherwise I would be able to send you to a website that would steal all of the files on your computer.

second, all you need to upload a file is an html form, where the user can select a file, then submit the form, thus uploading it to your server. a server side script is then needed to move the uploaded file to wherever you want it.

third, you should realllly be careful about allowing uploads to your server, as this can be a gaping vector for malware to be installed on your server if not done correctly.

fourth, since you are using django as your server side language, you will probably just want to google "uploading files using django". Here is the django documentation on how to do file uploads:

https://docs.djangoproject.com/en/dev/topics/http/file-uploads/?from=olddocs

这篇关于如何轻松上传文件到一个服务器使用JavaScript(傻瓜)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆