Welcome Guest, Not a member yet? Register   Sign In
[Solved] Image Manipulation Class
#1

(This post was last modified: 01-18-2020, 08:54 AM by PHS.)

Hello!
I am trying to implement the image manipulation library in my controller. But when I try to use the base_url() path, the library cannot find the path!
Code:
$path_save = base_url('assets/images/test.jpg');

            $image = \Config\Services::image()
           ->withFile($image_file->getTempName())
           ->fit(100, 100, 'center')
           ->save($path_save);

What is the difference in using the path to the directory where the image will be saved like this:

Code:
base_url('assets/images/test.jpg')

and this way:

Code:
'../public/assets/images/test.jpg'

Is there a correct way to indicate the directory path to save the image?
Reply
#2

(This post was last modified: 01-17-2020, 11:05 PM by Dedov_Evgeniy.)

$path_save = ROOTPATH . 'public/assets/images/test.jpg';
or
   $path_save = FCPATH . 'assets/images/test.jpg';

https://codeigniter4.github.io/userguide...-constants
Reply
#3

(This post was last modified: 01-17-2020, 11:08 PM by littlej.)

Hello mate !

When using "../", the path is relative to the location of the file on the server.
When using "base_url", the path is relative to the public location of the file.

"base_url" will add "https://my.domain.com/" in front, which means that the file must be publicly accessible, and must be located in the "public" folder.

For instance, if we want to include a php file, we will do "include APPPATH. 'Libraries/myfile.php';". But you can not do something like "include base_url ('../app/Libraries/myfile.php');" because the "app" folder is not publicly accessible.

So, it is "normal" that base_url is not working. It is used when you want to provide a public link (a link that will probably be displayed on the page for the final user).

You probably don't want to use "base_url()" in your controller (at least for what you are doing).
Reply
#4

(01-17-2020, 10:54 PM)Dedov_Evgeniy Wrote: $path_save = ROOTPATH . 'public/assets/images/test.jpg';
or
   $path_save = FCPATH . 'assets/images/test.jpg';

https://codeigniter4.github.io/userguide...-constants

Hello Dedov_Evgeniy !


Your tip solved my problem.

Thanks!
Reply
#5

(01-17-2020, 10:57 PM)littlej Wrote: Hello mate !

When using "../", the path is relative to the location of the file on the server.
When using "base_url", the path is relative to the public location of the file.

"base_url" will add "https://my.domain.com/" in front, which means that the file must be publicly accessible, and must be located in the "public" folder.

For instance, if we want to include a php file, we will do "include APPPATH. 'Libraries/myfile.php';". But you can not do something like "include base_url ('../app/Libraries/myfile.php');" because the "app" folder is not publicly accessible.

So, it is "normal" that base_url is not working. It is used when you want to provide a public link (a link that will probably be displayed on the page for the final user).

You probably don't want to use "base_url()" in your controller (at least for what you are doing).

Thanks!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB