文件上传:要保存到的文件名称是什么? [英] File uploading: what should be the name of the file to save to?

查看:96
本文介绍了文件上传:要保存到的文件名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将文件上传控件添加到我的ASP.NET 2.0网页中,以便用户可以上传文件.文件将以用户的名字存储在服​​务器的文件夹中.我想知道在保存到服务器时命名文件的最佳选择是什么.需要考虑安全性,性能,处理文件的灵活性等.

I am going to add file upload control to my ASP.NET 2.0 web page so that users can upload files. Files will be stored in the server in the folder with the name as of the user. I want to know what is the best option to name the files when saving to server. Needs to consider security, performance, flexibility to handle files etc.

我现在正在考虑的选项:

Options I am considering now :

  1. 使用与输入文件名相同的名称进行上传
  2. 从输入文件名开始添加用户ID +随机数+文件名
  3. 创建随机数+当前时间(以秒为单位)并使用该数字保存文件.将有一张表格将此数字与用户上​​传的数字进行映射

还有其他吗?最好的方法是什么?

Anything else? What is the best way?

推荐答案

从不使用用户输入的文件名.不要使用用户名.改为使用用户ID(我假设您的用户具有唯一的ID).

NEVER EVER use user input for filenames. Don't use the username. User the user id instead (I assume your users have an unique id).

切勿使用原始文件名.使用解决方案编号3,加上用户ID代替用户名.

NEVER use the original filename. Use your solution number 3, plus the user id instead of the username.

为您提供信息,PHP几年前就存在一个漏洞:一个人可以伪造一个HTTP POST请求,该请求带有文件上传,文件名如"../../anything.php"和php _FILES数组中应该包含经过清理的值,但未检测到此类文件名,因此可以在文件系统中的任何位置写入文件.

For your information, PHP had a vulnerability a few years ago: one could forge a HTTP POST request with a file upload, and with a file name like "../../anything.php", and the php _FILES array, supposed to contain sanitized values, didn't detect these kind of file names, so one could write files anywhere in the filesystem.

这篇关于文件上传:要保存到的文件名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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