(php) - 帮助编写上传图像的脚本

发布于 2024-08-16 09:50:02 字数 411 浏览 4 评论 0原文

我正在尝试将图像上传到服务器上的目录。我正在使用 http://www.reconn.us/content 中找到的教程/view/30/51/

首先,这是使用 PHP 上传图像的好方法吗?

其次,我还将把信息存储在 MySQL 数据库中。处理与用户上传的同名图像的好方法是什么?例如,如果用户连续上传文件“test.png”两次,那么第二个文件名会发生什么情况?从上面的脚本中,两者都将获得唯一的文件名,但作为用户我将如何再次访问该图像?我不能只是查询,因为我知道的唯一名称是我给它的重复名称,而且我绝对不知道服务器使用上传时间给它的唯一名称......

第三,什么是好的最大文件大小对于图像?

I am trying to upload an image to a directory on a server. i'm using the tutorial found at http://www.reconn.us/content/view/30/51/.

First, is that a good method for uploading images using PHP?

Second, I'm also going to store the info in a MySQL database. What is a good way to deal with images that have the same name that the user uploads? For example, if a user uploads a file 'test.png' 2x in a row, what should happen to the second filename? From the script above, both will get a unique filename, but how would I as the user access that image again? I couldn't just query because the only name I know was the duplicate name I gave it, and I definitely don't know the unique name the server gave it using the upload time...

Third, what is a good max file size for images?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

想你只要分分秒秒 2024-08-23 09:50:02

您可以在上传后向用户报告唯一的 URL,以便用户知道在哪里可以找到该图像。因此,第一个 test.png 可能是 http://www.example.com/images/fjdklagjsdl .jpg 第二个可能是 http://www.example.com/images /jklfsdlkj.jpg

您还可以为用户提供某种界面来查看他们上传的图像。如果您在图像的唯一文件名旁边显示上传图像的缩略图,用户将很容易识别哪个图像是哪个。

You can report the unique URL back to the user after the upload so that the user will know where to find the image. So, the first test.png could be http://www.example.com/images/fjdklagjsdl.jpg and the second could be http://www.example.com/images/jklfsdlkj.jpg

You can also provide some kind of interface for users to view images they've uploaded. If you display a thumbnail of the uploaded image next to the image's unique filename, it will be easy for the user to identify which image is which.

童话 2024-08-23 09:50:02

这是我使用的方法:

  1. 用户上传图像

  2. 服务器使用唯一的(GUID或其他)文件名保存图像并存储 - 唯一生成的文件名和原始上传的文件名在数据库中

  3. 图像使用链接到图像表的original_filenameunique_filename或primary_key。

图像从服务器获取,并使用数据库中存储的原始文件名提供服务。这样您就可以避免文件名冲突的机会,并保留图像的原始文件名。此外,这还允许您在 original_filename 列上构建搜索以供用户使用。

使用此方法,无需向用户公开唯一的文件名,而是使用它们来查找与“images”中的特定 idoriginal_filename 关联的图像桌子。

当然,如果您不介意在显示图像时为其提供原始文件名,则可以在存储时生成唯一的文件名。

This is the method I use:

  1. Users upload images

  2. Server saves the image with a unique (GUID or something) filename and stores - both - the unique generated filename and the original uploaded filename in a database

  3. Images are linked to using either the original_filename, unique_filename or primary_key for the images table.

The images are taken from the server, and served using the original filename stored in the database. This way you avoid chances of conflicting filenames and you preserve the image's original filename. In addition, this allows you to build a search on the original_filename column for the user to use.

With this method, unique filenames never have to be exposed to the user, instead they're used to locate the image associated with a specific id or original_filename in the 'images` table.

Of course, if you don't care about giving the original filename to the image when it's displayed, you can just generate a unique filename whenever you want to store it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文