search

Home  >  Q&A  >  body text

php - laravel how to deal with the problem that users can only access the pictures they uploaded

How to deal with laravel users can only access the pictures uploaded by themselves

阿神阿神2725 days ago701

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-10 09:49:27

    First of all, the uploaded pictures must be marked with which user uploaded them. This can be stored in the database.
    In fact, you can write a middleware for accessing images. Before actually accessing the image, you can determine whether the image belongs to the current accessing user, and then provide different processing

    reply
    0
  • 高洛峰

    高洛峰2017-06-10 09:49:27

    1. Record the user who the picture belongs to

    2. Judge before accessing. Add middleware to the controller that accesses the image.

    reply
    0
  • 黄舟

    黄舟2017-06-10 09:49:27

    First of all, you can only view the pictures you uploaded. What is the difference between it and the photo album?
    You create a table and save the user and attributes corresponding to the image
    Then use the middleware to determine whether the user this image belongs to is the current logged-in user

    When you click on the picture, you will definitely get the picture ID or something, and then check the user ID and compare it with the currently logged-in user. If it is inconsistent, just return false!

    reply
    0
  • Cancelreply