Home > Mobile >  Where to save user uploaded images in CodeIgniter?
Where to save user uploaded images in CodeIgniter?

Time:01-30

What I want to do is let a user save an image and when they're accessing their accounts I want the image to display.

  1. What I'm currently doing is I'm saving the images in public folder
  2. Store the path to the database Path: css\img\myPic.jpg
  3. Display the image
    <img src='esc($empInfo['img'])' style="height: 200px; width: 200px">

But since this is a public folder I can't save personal pictures in this folder

I also tried saving the path to writable\uploads\myPic.jpg but no luck

CodePudding user response:

As of the the moment. the solution that I got is "copying" the file(in my case it is an image file)from writable/uploads to public using Publish Library.

    $publisher = new Publisher(WRITEPATH . 'uploads', FCPATH. 'img/');
    $publisher->addPaths([
        'img/myPic.jpg',
    ]);
    $publisher->copy(true); // `true` to enable overwrite
  • Source Path: WRITEPATH . 'uploads'
  • Destination Path: FCPATH. 'img/'
  • Source File: img/myPic.jpg

Now you can ref the image in img tags.

Next step should be replacing/deleting the image after use, because this is not gonna be different when you upload the image at public folder. Will try to update if I found a solution

Source: https://codeigniter.com/user_guide/libraries/publisher.html

PS. Feel free to correct me :) I am also new to web developing in general

CodePudding user response:

If you look for a manual or a concept , you can also try this:

  1. You must have some folder where you store all personal images
  2. When user needs it, copy the file into Public folder with a random generated 32 character name (GUID type) but with the original extension.
  3. Then feed it to the user in the view.
  4. Once displayed after the view is called you can delete the image from that folder.
  • Related