如何将用户照片大量上传到MySQL数据库

发布于 2025-01-24 16:20:54 字数 232 浏览 3 评论 0原文

我正在使用使用PHP和MySQL的用户管理系统。(XAMPP) 它在名为“用户”的表中具有大约1000多种用户记录,其中“ ID”为主要键。 其中一列是“头像” 我有一个带有1000多个JPG图像的文件夹。所有用户图像均由其ID命名。例如,如果一个名为jon的用户ID = 222他的照片将为222.jpg

我要做的就是使用图像名称将所有照片上传到表格中的正确用户ID,

什么是最好的方法可以接受吗? 希望它清楚并提前感谢

I'm working on a user management system that uses PHP and mysql.(XAMPP)
it has around 1000+ user records in A table called "users" with "id" as primary key.
one of the columns is "avatar"
I have a folder with 1000+ jpg images. all user images are named by their ids. for example if a user named Jon with id=222 his photo will be 222.jpg

what I want to do is upload all photos to their users using the image name to be put to the correct user id in the table

what's the best approach I can take?
hope its clear and thanks in advance

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

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

发布评论

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

评论(1

城歌 2025-01-31 16:20:54

我有一些您可能会执行的步骤:

  1. 照常上传文件,但是在此步骤中,您必须将用户ID作为参数

    包含

  2. 重命名文件之前,请先保存图像,示例:

      $ user-> id。时间() 。 '。' 。 $ file-> getClientExtension();
     
  3. 将其上传到文件夹

  4. 保存到您的表格

I have some steps that you might do :

  1. Upload file as usual, but in this step you must include user id as parameter

  2. Query user by id

  3. Rename file before save image, example :

    $user->id . time() . '.' . $file->getClientExtension();
    
  4. Upload it to folder

  5. Save to your table

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