允许(file-)webserver上的UTF-8编码文件名? [英] allow UTF-8 encoded filenames on (file-)webserver?

查看:216
本文介绍了允许(file-)webserver上的UTF-8编码文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在托管一个小型文件服务器,用户可以从世界各地上传文件。

I am hosting a small fileserver, where users can upload documents from all around the world.

由于编码问题(请参阅 otherquestion ),我问自己是否禁止用户上传(另一方面下载)CP1252字符集不支持的文件?

Due to problems in encoding (see otherquestion), I am asking myself if I should disallow users to upload (and on the other hand download) files not supported by CP1252 charset?

或其他;允许用户在其文件名中上传阿拉伯文或中文字母的文件是否有意义?

or otherwise; is it senseful to allow users upload documents with arabian or chinese letters in their filenames?

PS:他们稍后下载相同的文件(应该具有相同的文件名如上所述)

PS: they download the same file some time later (and it should have the same filename as uploaded)

推荐答案

您应该使用随机生成的名称将文件存储在磁盘上,或者让文件名基于文件内容的散列(也适用于重复数据删除存储)。您可以将原始文件名作为元数据保存在数据库中,以及与文件相关的所有其他元数据(上传文件名以及类似内容)。然后,使用PHP脚本再次提供该文件,该脚本在HTTP头中从数据库中设置原始文件名。这样你:

You should be storing the files on disk using a randomly generated name, or let the file name be based on a hash of the file contents (good for deduplicating storage as well). You can save the original file name as meta data in a database together with all other meta data about the file (who uploaded it and things like that). Then you serve the file again using a PHP script which sets the original file name from the database in an HTTP header. This way you:


  • 不需要担心文件名称的清除或复制

  • 文件系统编码问题

  • 存储复制(如果使用哈希)

这篇关于允许(file-)webserver上的UTF-8编码文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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