duanan5940 2017-03-10 16:29
浏览 28

文件上传,限制大小最佳做法[关闭]

Hello developers every where,

i saw many articles and reddit posts about uploading best practices (this one of the posts)

the point i'm asking for is "Restrict file size. Not just big files, but small files. (DDOS yo!)", what does that mean?

is that mean that i have to make if condition in my code to check if size == 0 || size > max_size to show error message?

becase i can't add minimum limit of my files, i can't say that the minimun file size will be 1 Kb, because it may be very small text file or image.

so, what is the best practice to do that?

  • 写回答

1条回答 默认 最新

  • doubianyan9749 2017-03-10 16:36
    关注

    Generally speaking, it is a good idea to make sure that content that gets uploaded to your website meets minimum qualifications. Usually those restrictions are specific for each file type. Ex: resolution is at least 640x480 for images, file is not empty(hence minimum size limit), file header matches file extension etc.

    Additionally, some hosts limit number of files that you can have on your file system. Putting minimum size prevents people from writing a script that will instantly deplete your server's limits, or flood it with requests.

    All limits are set on case-by-case basis depending on your project requirements to protect users from themselves.

    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析