CodeIgniter Forums

Full Version: How to send an image to a specific part of website?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 !
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.
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.
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.
(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.