简体   繁体   English

在php / asp.net应用程序中保存/加载img /文件(word,excel等)的最佳方法是什么?

[英]What is the best way to save/load img/file(word,excel etc.) in php/asp.net application?

I'm currently a student and I aspire to become a great web developer :) 我目前是一名学生,我渴望成为一名出色的Web开发人员:)

I want to work on some 'practice' projects that is capable of storing/retrieving images or any type of file(.doc,.xcl,.txt, etc.). 我想从事一些“实践”项目,这些项目能够存储/检索图像或任何类型的文件(.doc,.xcl,.txt等)。 Some are saying that it's better to store img/any file in a file system as opposed to saving it inside the database. 有人说将img /任何文件存储在文件系统中比将其保存在数据库中更好。

I would like to know the pros and cons of both side. 我想知道双方的利弊。

I would also like to know what's the best data type for storing imgs/files in MySQL (I'm currently using longblob for PHP-MySQL) For saving imgs 我还想知道在MySQL中存储imgs /文件的最佳数据类型是什么(我目前在PHP-MySQL中使用longblob)来保存imgs

I would also like to know what's the best data type for storing imgs/files in SQL Server (I'm currently using Asp.net Varbinary(max) for SQL Server 2008) For saving imgs 我还想知道在SQL Server中存储imgs /文件的最佳数据类型是什么(我目前在SQL Server 2008中使用Asp.net Varbinary(max)) 用于保存imgs

Lastly,I'm just curious on how websites like facebook and other big web applications store imgs and files. 最后,我很好奇Facebook和其他大型网络应用程序之类的网站如何存储img和文件。

Sir/Ma'am, your answers would be of great help and be very much appreciated. 先生/女士,您的回答将为您带来很大的帮助,我们将不胜感激。 Thank you++ 谢谢++

Facebook uses haystack for images. Facebook使用干草堆拍摄图像。

Here is a link from their site describing image storage and retrieval 这是他们网站上的链接,描述了图像的存储和检索

http://www.facebook.com/note.php?note_id=76191543919 http://www.facebook.com/note.php?note_id=76191543919

Based on prior experience, I would recommend not storing files directly into a SQL database. 根据以前的经验,我建议不要将文件直接存储到SQL数据库中。

Pros: Storing in database 优点:存储在数据库中

  • Files are saved "forever" 文件“永久保存”

  • Can restrict access to the real file more easily 可以更轻松地限制对真实文件的访问

  • You can, technically, check for duplicate files. 从技术上讲,您可以检查重复的文件。

  • You are not keeping the files on drive, so it can be faster to access for the server 您没有将文件保留在驱动器上,因此可以更快地访问服务器

  • Less files on your server is considered "better" and more organized 服务器上的文件更少被认为是“更好”的文件,井井有条

  • "one file for everything" “一应俱全”

Cons: 缺点:

  • If site is up but database is not, file will be invalid (through "direct" linking) 如果站点已启动但数据库未启动,则文件将无效(通过“直接”链接)

  • Some databases that cannot be reconfigured only allow blobs to be of a certain size limit (a few mb), therefore making it so that really large images cannot be stored (but can be separated) 某些无法重新配置的数据库仅允许将blob限制在一定的大小限制(几mb),因此使其无法存储(但可以分开)非常大的图像

  • More data becomes stored in memory when loading file to (to a variable); 将文件加载到(到变量中)时,更多数据将存储在内存中; similar to the problem above, very large images can slow down your server. 与上述问题类似,非常大的图像会降低服务器的速度。

  • Some files may be of different character encoding, and thus storing and/or retrieving files may corrupt the original file. 某些文件可能具有不同的字符编码,因此存储和/或检索文件可能会损坏原始文件。 I am not sure if this is real problem, but I think it was. 我不确定这是否是真正的问题,但我认为是。

I personally suggest you to do not store files on my database anymore because of the cons. 我个人建议您不要再将文件存储在我的数据库中,这是有缺点的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM