CodeIgniter Forums
How to send an image to a specific part of website? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How to send an image to a specific part of website? (/showthread.php?tid=69999)



How to send an image to a specific part of website? - rickyboy - 02-07-2018

Hi sir/ma'am, I wanna ask how can I do this on CodeIgniter, where I can upload an image then after that it will display on the sidebar. Let's say I had may dropdown for locations for that specific image before to upload and when select location (e.g homepage sidebar) and finish uploading then it will display on homepage sidebar  Confused thank you so much for the help !


RE: How to send an image to a specific part of website? - InsiteFX - 02-07-2018

You would need to save the image name and path to the database then do
a redirect back to the page with a refresh.

You would also need a method in the controller for loading the sidebar images
from the database.


RE: How to send an image to a specific part of website? - rickyboy - 02-07-2018

Thank you sir, but how can I send that image to that specific position on the website? should I make div tags with ID's and echo the image path redirect on that div tags? sorry sir, I cant execute it properly.


RE: How to send an image to a specific part of website? - InsiteFX - 02-07-2018

You can do it something like this its just an example:

PHP Code:
// -----------------------------------------------------------------------

/**
 * htmlImage
 * 
 * Place in a CI Helper
 * 
 * TODO: Add Eror Handling...
 */
if ( ! function_exists('htmlImage'))
{
 
   /**
     * htmlImage ()
     * -------------------------------------------------------------------
     *
     * $image = assign the database image path and name here
     * IE: http://www.yoursite.com/assets/images/image01.png
     * 
     * $alt   = 'Alt Image Name';
     * 
     * $data['image'] = htmlImage($image, $alt);
     * 
     * You can now access the image in the html view
     * 
     * <?php echo $image; ?>
     * 
     * @param  string $image
     * @param  string $alt
     * @return string
     */
    
function htmlImage(string $image ''string $alt '') : string
    
{
     
   $out '';

 
       $out .= '<img src="'.$image.'" alt="'.$alt.'" />';

        return 
$out;
    }


Read the comments.


RE: How to send an image to a specific part of website? - rickyboy - 02-07-2018

(02-07-2018, 03:56 AM)InsiteFX Wrote: You would need to save the image name and path to the database then do
a redirect back to the page with a refresh.

You would also need a method in the controller for loading the sidebar images
from the database.

(02-07-2018, 10:14 AM)InsiteFX Wrote: You can do it something like this its just an example:

PHP Code:
// -----------------------------------------------------------------------

/**
 * htmlImage
 * 
 * Place in a CI Helper
 * 
 * TODO: Add Eror Handling...
 */
if ( ! function_exists('htmlImage'))
{
 
   /**
     * htmlImage ()
     * -------------------------------------------------------------------
     *
     * $image = assign the database image path and name here
     * IE: http://www.yoursite.com/assets/images/image01.png
     * 
     * $alt   = 'Alt Image Name';
     * 
     * $data['image'] = htmlImage($image, $alt);
     * 
     * You can now access the image in the html view
     * 
     * <?php echo $image; ?>
     * 
     * @param  string $image
     * @param  string $alt
     * @return string
     */
    
function htmlImage(string $image ''string $alt '') : string
    
{
     
   $out '';

 
       $out .= '<img src="'.$image.'" alt="'.$alt.'" />';

        return 
$out;
    }


Read the comments.

Thank you so much sir  Big Grin god bless.