CodeIgniter Forums
Image not showing in codeigniter 4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Image not showing in codeigniter 4 (/thread-74782.html)

Pages: 1 2


Image not showing in codeigniter 4 - durairaj - 11-06-2019

<img src="<?=WRITEPATH.$value->avatar?>">

this image not displaying

but when i open D:\xampp\htdocs\apptsys\writable\uploads/avatar\avatar_1.jpg link on browser image showing.

After i put directly link in img and not displaying 
<img src="D:\xampp\htdocs\apptsys\writable\uploads/avatar\avatar_1.jpg">

Please help ,


RE: Image not showing in codeigniter 4 - Chivinsdev - 11-06-2019

(11-06-2019, 12:19 AM)durairaj Wrote: <img src="<?=WRITEPATH.$value->avatar?>">

this image not displaying

but when i open D:\xampp\htdocs\apptsys\writable\uploads/avatar\avatar_1.jpg link on browser image showing.

After i put directly link in img and not displaying 
<img src="D:\xampp\htdocs\apptsys\writable\uploads/avatar\avatar_1.jpg">

Please help ,

Hello try this I think it will help you get the image. It work for me
PHP Code:
<img src="<?php echo base_url('uploads/avatar/'.$value->avatar); ?>"

But I will prefer you use another location for you files since writable folder is temporal for files.
Use some thing like
PHP Code:
<img src="<?php echo base_url('.public/uploads/images/users/'.$user->avatar);?>"

Instead of saving to the writable folder.
I hope this will help you and others here


RE: Image not showing in codeigniter 4 - Digital_Wolf - 11-06-2019

All files in the "writable/uploads" folder should be temporary. Usually there is placed avatars user which only that uploaded on server, but still not typically recognized process and shifting in folder "public/assets", if anything you must use function
PHP Code:
<= base_url($value - >avatar)?>



RE: Image not showing in codeigniter 4 - kilishan - 11-06-2019

(11-06-2019, 12:19 AM)durairaj Wrote: <img src="<?=WRITEPATH.$value->avatar?>">

this image not displaying

but when i open D:\xampp\htdocs\apptsys\writable\uploads/avatar\avatar_1.jpg link on browser image showing.

After i put directly link in img and not displaying 
<img src="D:\xampp\htdocs\apptsys\writable\uploads/avatar\avatar_1.jpg">

Please help ,

This is not a valid URL as far as the browser is concerned when part of an HTML page D:\xampp\htdocs\apptsys\writable\uploads/avatar\avatar_1.jpg.

Also, if you're using the default configuration of CI and serving from the public folder as intended, the writable directory is not accessible from the web. You'll need to either save the files somewhere they're publicly available, or create a new route that acts as a proxy to the images. The second option isn't a bad way, since that allows you to build in other potential restrictions if needed, but also uses more server resources.


RE: Image not showing in codeigniter 4 - John_Betong - 11-06-2019

I would hard a guess and think the image is being called from the public folder... If so and you really want to use the WRITEPATH folder then try using s relative path which should be converted to an URL:

<img src="../writable/uploads/avatar/avatar_1.jpg">

I will try it to make sure it works when I am back on the desktop.

As mentioned far better to group all callable files into a common folder:

/public_html/assets/
css/
img/
js/
svg/


RE: Image not showing in codeigniter 4 - durairaj - 11-06-2019

(11-06-2019, 06:40 PM)John_Betong Wrote: I would hard a guess and think the image is being called from the public folder... If so and you really want to use the WRITEPATH folder then try using s relative path which should be converted to an URL:

<img src="../writable/uploads/avatar/avatar_1.jpg">

I will try it to make sure it works when I am back on the desktop.

As mentioned far better to group all callable  files into a common folder:

/public_html/assets/
css/
img/
js/
svg/

This is not working..


RE: Image not showing in codeigniter 4 - John_Betong - 11-06-2019

(11-06-2019, 09:54 PM)durairaj Wrote:
(11-06-2019, 06:40 PM)John_Betong Wrote: I would hard a guess and think the image is being called from the public folder... If so and you really want to use the WRITEPATH folder then try using s relative path which should be converted to an URL:

<img src="../writable/uploads/avatar/avatar_1.jpg">

I will try it to make sure it works when I am back on the desktop.

As mentioned far better to group all callable  files into a common folder:

/public_html/assets/
css/
img/
js/
svg/

This is not working..

It sort of works for me because I store an SVG image in the writable folder and echo the SVG file contents.

The IMG requires a valid URL and WRITEPATH is above the root and not accessible.

Use "Plan B" - store all images in /public_html/assets/imgs/ folder.


RE: Image not showing in codeigniter 4 - durairaj - 11-06-2019

This is not working ,i don't know how to store images in public folder, $avatar->move( base_url().'/public/assets/avatar', $name ); this popped with index.html not found on directory.
i'm not able to show uploaded images if someone has example pls let me know.thank you.


RE: Image not showing in codeigniter 4 - John_Betong - 11-06-2019

Try this:
1. index.php -> echo $PATH = getcwd(); die;
2. make a note of the $PATH;
3. create this folder: $PATH .'\assets\avatar'
4. save this avatar file: $PATH .'\assets\avatar\avatar_1.jpg'
5. test: index.php -> echo '<img src="/assets/avatar/avatar_1.jpg" alt="#" width=333 height=333 >';

Edit:
If that does not work and the image file is saved in the correct path then there is most likely to be a problem with .htaccess file. If so temporarily rename .htaccess file and try again.

Also in index.php temporarily add these lines:
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');

echo '<img src="/assets/avatar/avatar_1.jpg" alt="#" width=333 height=333 >';
die;


RE: Image not showing in codeigniter 4 - durairaj - 11-07-2019

(11-06-2019, 11:30 PM)John_Betong Wrote: Try this:
1. index.php -> echo $PATH = getcwd(); die;
2. make a note of the $PATH;
3. create this folder: $PATH .'\assets\avatar'
4. save this avatar file: $PATH .'\assets\avatar\avatar_1.jpg'
5. test: index.php -> echo '<img src="/assets/avatar/avatar_1.jpg" alt="#" width=333 height=333 >';

Edit:
If that does not work and the image file is saved in the correct path then there is most likely to be a problem with .htaccess file. If so temporarily rename .htaccess file and try again.

Also in index.php temporarily add these lines:
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');

echo '<img src="/assets/avatar/avatar_1.jpg" alt="#" width=333 height=333 >';
die;
thanks man ,i will try

(11-07-2019, 12:23 AM)durairaj Wrote:
(11-06-2019, 11:30 PM)John_Betong Wrote: Try this:
1. index.php -> echo $PATH = getcwd(); die;
2. make a note of the $PATH;
3. create this folder: $PATH .'\assets\avatar'
4. save this avatar file: $PATH .'\assets\avatar\avatar_1.jpg'
5. test: index.php -> echo '<img src="/assets/avatar/avatar_1.jpg" alt="#" width=333 height=333 >';

Edit:
If that does not work and the image file is saved in the correct path then there is most likely to be a problem with .htaccess file. If so temporarily rename .htaccess file and try again.

Also in index.php temporarily add these lines:
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', '1');

echo '<img src="/assets/avatar/avatar_1.jpg" alt="#" width=333 height=333 >';
die;
thanks man ,i will try
thanks a lot. you helped me lot,no words to say thank you.it's working