how to mass Upload user photos to mysql database

56 Views Asked by At

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

1

There are 1 best solutions below

0
yogastama On

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