PHP如何上传中文名文件?
我有学习门户(LMS),我将在其中上传文档、图像、视频等来创建内容。如果上传的文件有中文名称,则不会上传。相反,会上传具有垃圾名称的损坏文件。
例如,我尝试上传一个名为地球科学.jpg的文件。但在服务器上,我得到的文件为 地çƒç§'å¡.jpg。此外,上传的文件在服务器中已损坏。
我希望该文件在服务器上以相同的名称上传。 因为我想搜索这些文件并稍后重复使用以创建内容。
供参考: 我在 Windows XP 上安装了 XAMPP 服务器。 安装了中文、韩语和日语语言包。
感谢您的回答。
I have learning portal(LMS) where I will upload documents, images, videos etc to create content. If the file being uploaded has a chinese name then it is not getting uploaded. Instead a corrupted file with junk name is uploaded.
For example, I tried to upload a file named 地球科学.jpg. But on the server I got this file as 地çƒç§‘å¦.jpg. Also the uploaded file is corrupted in the server.
I want this file to get upload with the same name on the server.
Because I want to search for these files and reuse later for creating content.
FYI:
I have XAMPP server installed on Windows XP.
Chinese, Korean, and Japanese language packs installed.
Thanks for your answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
据我所知 ntfs 无法处理文件系统上的某些字符。我建议使用通用名称存储文件。
例如,您可以创建一个包含两列的表:名称和文件,作为名称,您保存原始名称,作为文件,您设置类似 md5(name) 的内容。
AFAIK ntfs can't handle some characters on the filesystem. I would suggest to store the file with a generic name.
for example you could create a table with two columns: name and file, as name you save the original name, and as file you set something like md5(name).
如果您需要名称来搜索它,请使用数据库来存储名称信息和文件位置,并使用您自己的约定保存文件。
示例
当您搜索时,您使用数据库来查找给定的文件名和位置。在构建图像存储解决方案时,分离存储逻辑很常见,不仅是为了命名问题,也是为了考虑文件夹中累积的文件数量的限制/限制。
If you need the name to search for it use a database to store name information and the file location and save the file using your own convention.
Example
When you search you use the db to locate a given file name and location. Separation storage logic is something common when building image storage solutions not only for naming problems but also for limitations/spped considerations in terms of the number of files that accumulate in folders.
使用
iconv
或mb_convert_encoding
更改字符串编码。Use
iconv
ormb_convert_encoding
to change character string encoding.确保显示表单的页面以 utf-8 或更高版本呈现,通常这可以完成工作,您还可以选择使用表单元素的
accept-charset
属性来指示发布的数据是作为指定的字符集发送。不确定这是否能完成工作,请告诉我。
Make sure the page displaying the form is rendered in utf-8 or higher, usually this does the job, you can also choose to use the
accept-charset
attribute of the form element to indicate the posted data is sent as the specified charset.Not sure if this all will do the job, let me know.
我认为您可能想要使用某种数据库解决方案,特别是当您稍后需要搜索文件时。使用数据库,您可以避免 I/O 开销。
I think you might want to use somekind of database solution, especially when you need to search files later on. With database you can avoid I/O overhead.
我认为您必须先了解/了解文件的字符集,然后才能确定如何处理上传。恐怕我对非欧洲字符集不太熟悉,也不知道哪些字符集使用最广泛。
UTF-8 应该是一个安全的选择,可以处理几乎所有你想扔给它的东西。我最近在博客上写的一篇文章中提供了一些对配置应用程序有用的相关信息:如何避免 PHP 中的字符编码问题
I think you must learn/understand what character set the file is in before you can work out how to handle the upload. I'm afraid I'm not too familiar with non-european character sets and don't know which are most widely used.
UTF-8 should be a safe bet to handle almost whatever you care to throw at it. There's some relevant information that could be useful in terms of configuring your application in a post I wrote recently on my blog: How to Avoid Character Encoding Problems in PHP