CodeIgniter Forums
Image to public or writable folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Image to public or writable folder (/showthread.php?tid=81497)



Image to public or writable folder - snelledre - 03-12-2022

All,
The documentation gives a example and that is the standard that file/images will stored in de writable folder for example the uploads folder.
But reading here in the forum they say store it in the public folder.
Why in the public folder and not in the standard folder named writable?
The writable folder is save for the outside world and the public folder is accessible for everyone in my opinion.

Andre


RE: Image to public or writable folder - seunex - 03-12-2022

I will advise you to save to public folder because image need to be publicity accessable.


RE: Image to public or writable folder - AnastasiaAniL12 - 03-12-2022

The documentation gives a example and that is the standard that file/images will stored in de writable folder for example the uploads folder.
But reading here in the forum they say store it in the public folder.


RE: Image to public or writable folder - seunex - 03-12-2022

Yea we all aware of that because if u try to upload the image to writable folder and try to access it the system will return a relative path to the image instead of norm image url we all use with. Use FCPATH.'path/to/director ' do not use WRITABLE.'path/to/directly '.

Anyway your choice.


RE: Image to public or writable folder - snelledre - 03-12-2022

(03-12-2022, 11:41 AM)seunex Wrote: Yea we all aware of that because if u try to upload the image to writable folder and try to access it the system will return a relative path to the image instead of norm image url we all use with. Use FCPATH.'path/to/director ' do not use WRITABLE.'path/to/directly '.

Anyway your choice.

I use an method to show the image from the writable folder.

PHP Code:
public function image($image=null)
    {
        if ($image) {
            
            $path 
WRITEPATH 'uploads/installation_images/' $image;
        
            $finfo 
= new \finfo(FILEINFO_MIME);
            
            $type 
$finfo->file($path);
            
            header
("Content-Type: $type");
            header("Content-Length: " filesize($path));
            
            readfile
($path);
            exit;
        }
    }


All you see in the html is:

<
img src="/admin/installations/1647118918_0617c078466e88edf636.jpg/image" width="200" height="200" alt="" class="mb-3" name="image" id="image"