Welcome Guest, Not a member yet? Register   Sign In
Is there a way to create a symbolic link within the public folder?
#1

Hi,
I am working on an application that will enable admin users to upload images to be used inside posts. Is there a way to tell the application that for example the public/images folder is not inside the public folder but let's say /home/user/myproject/sharedassets/images which is the server's path (the codeigniter application being inside the folder myproject) ? 
Thanks for your help
Reply
#2

(This post was last modified: 07-11-2024, 05:16 AM by captain-sensible.)

seems a complicated approach , with capacity for broken URL .

First to display any image in any post all you need is the image name and where it is.

Im my blog article I get image displayed using

Code:
<img src =".base_url('blogImages')."/".esc($blog['image']).">

that code is in a view that will display a blog article
Code:
$blog['image'];
// the above gets just the name of an image wich is stored in a field in a database
// i.e  "someimage.jpg" is stored  on the basis of text, in a field in a databse , alomg with blog article, id etc

all blog images are stored in a directory called blogImages. so i use constant base_url() and that directory name to reference image

Code:
base_url('blogImages')
//base_url() eqautes to public directory, so blogImages is a direcvtory in public

ways of getting stuff dfrom reuest have chnagedf i think but here is a legacy



Code:
$this->imageFile = $this->request->getFile('userfile');
$this->imageFileName = $this->imageFile->getName();
//thr above if memory serves me well gets image foole name ; once known the name can be put in a databse


step to shift image to where i want
Code:
     $this->imageFile->move('blogImages',    $this->imageSlug );
$this-imageSlug, is the name i want to give to image , after any white space in image name has been removed and bad chars
maybe if you had a directory : sharedassets/images at root of web app at least if it was moved all should be Ok with relative paths
then :
Code:
$this->imageFile->move(ROOTPATH.'sharedassets/images ',    'name you want ot give image ');
CMS CI4 A CMS system, runs out of the box written on top of CI4
Arch Book  CodeIgniter4 on Apache(pages 92-114) 
Reply
#3

The reason I am looking for a solution is so I can make upgrades on the application without risking to loose uploaded files. I used this structure with rails applications in the past, all assets remaining stored independently. That was very flexible for deploying new app releases.

While searching, it looks like what might answer my needs is to use the publisher library https://codeigniter.com/user_guide/libra...isher.html .

Looking at the examples, it feels like what this does basically is to copy files from a folder into the public one, so that duplicates files on the server side. Am I correct? Would there be a solution to not duplicate the files?
Reply
#4

You cannot make files not in public/ accessible from the browser.
Alternatively, you should write your own handler to read the file and send a Response (https://www.php.net/manual/en/function.readfile.php).
But this will cause an additional load on the disk.
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#5

Thanks for confirming the impossibility. I will try to use the publisher library to see if I manage to do something with it (if anyone has a example I can look at in addition to those in the documentation, that'd be super helpful).
Reply
#6

Simple copy-paste files
https://github.com/neznaika0/codeigniter...Publishers
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#7

Why don't you just create a symlink in the public folder?


Code:
$ cd public/
$ ln -s ../sharedassets/images .
Reply
#8

@kenjis I tried but files do not appear in the browser. Thanks @ozornick  I will try following your example (that expenses app you made is pretty useful).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB