Image not retrieve from folder - codeigniter

I am upload the image into database and folder. But when I am trying to retrieve it it will not working.
My code is as below:
<img src="<?php echo APPPATH.'modules/employee/image/'.#$userdata[0]->photo;?>" />
Give me a solution.

Try:
<img src="<?php echo base_url().'modules/employee/image/'.#$userdata[0]->photo;?>" />

Constant APPPATH will not give you full path, you must need to use base_url() instead, but for using base_url() you also need to define your base_url in config.php

Related

base url is getting calling an inner folder

When I use echo base_url() in some portions of the application, it works fine.
My base_url() is http://localhost:8080/appname/
But when I do this <?php echo base_url(); ?>data/profile/avatar-5.png
The url appears like http://localhost:8080/appname/admin/data/profile/avatar-5.png where admin is a folder. I guess its because from where it is called from. But yet the base_url() should actually give the right url. Any ideas?
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php:
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Also don't forget to set base_url in application/config/config.php
$config['base_url'] = "http://localhost:8080/appname/';
Then try
<?php echo base_url('data/profile/avatar-5.png'); ?>
If the base path is not working for you, you can try my solution which I usually use
Create an separate path for logo or image
$config['image_path'] = ' http://localhost:8080/appname/admin/data/profile/';
use that in you view controller as
echo $this->config->item('image_path').$imagename;

Img Src path adding / when using .SVG in Cakephp

For some reason unknown to me when I try to use a .svg file in the image src path cakephp adds an additional / to the file path which shows the image as missing.
example:
<img src="<?php e($html->url('/img/mobile/shark.svg')); ?>"
outputs:
<img src="host/img/mobile/shark.svg/"
It then thinks the file is not there. But when I remove the / in chrome inspect the file appears. Anyone see this issue before?
Update 5/1
On Cake 1.3, and beyond our control at the moment to update. These helpers just break the page =( and after looking at the documentation for 1.3 it looks like it should not.
Create a image tag using cakephp helper,
<?php echo $this->Html->image('example.svg', array('alt' => 'CakePHP')); ?>
Output will be
<img src="/img/example.svg" alt="CakePHP" />
Look HtmlHelper::image(string $path, array $options = array())
You should use the CakePhp HTML helper.
<?php echo $this->Html->image('image.svg', array('alt' => 'image')) ?>

Codeigniter base_url() in whack?

I was trying to set up a basic log in form with a following code:
<?=form_open(base_url() . 'main/login'); ?>
However after submitting the form the url shows this:
example.com/main/http//example.com/http//example.com/main/login
So I guess in essence for some reason the base-url is printed twice before the controller/method declaration. If I clear the base url value in my config file then the application works normally. I am however curious on what could cause this. For additional information I am working on xampp with a virtualhost and I have mod-rewrite on with a .htaccess file located at the document root.
CodeIgniter automatically adds the base_url to the action of the form when you use the form helper.
For example, you can use:
<?=form_open('main/login'); ?>
which will produce:
http//example.com/main/login
And a correct URL! Pretty simple! :D
More information at:
http://codeigniter.com/user_guide/helpers/form_helper.html
The file config.php under application/config has the setting:
$config['base_url'] = '';
Give it the folder/directory path. For example:
$config['base_url'] = 'http://localhost/ci_test/';
Don't forget to mention the protocol (http://). Alternatively try the site_url() method instead of base_url() for form opening. Skip it if using the form_open() function:
<form action="<?php echo site_url('main/login'); ?>"> ... </form>
Or
<?php form_open('main/login'); ?>
For more help: http://codeigniter.com/user_guide/helpers/url_helper.html
Not sure about the .htaccess file you have used. But this might be the answer codeigniter: why is that when i echo base_url() in an href attribute of an anchor tag, it echoes twice
Try it by parameter:
<?=form_open(base_url('main/login')); ?>
or
<?=form_open site_url('main/login')); ?>
In order to append the prefix also
You can Use
<?php echo form_open(base_url(main/login)); ?>
You have to use "echo" rather than because it not works in some browsers....

how can I change the header logo to link to an external website in magento?

I'm trying to achieve the following:
our client needs the header logo of his magento site to take him to another website (different domain).. I have tried to alter header.phtml but the link is becoming: www.websitedomain.com/index.php/www.otherdomain.com
what I want is simply to navigate to www.otherdomain.com
how is that possible?
You will want to change the link in the image to go to the appropriate location.
I believe the file should be located in:
/app/design/frontend/yourtemplate/yourtemplate/page/html/header.phtml
use http:// like bellow
http://www.otherdomain.com in your anchor tag
Just in case someone else comes here looking for the answer, in the file named above, at line 105 (v1.9.2) -
Add the url as below
<h1 class="logo"><strong class="no-display"><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $logo_src ?>" alt="<?php echo $this->getLogoAlt() ?>" /></h1>

codeigniter image path

I am a codeignite newbie and tried to add an image in my file under view folder.
I add <img src="../images/myImage.jpg"></img> to my service_view.php. All I can see is a broken link of a small icon.
however, if I change my path to
<img src="../../user_guide/images/myImage.jpg"></img>
I can see the image.
My file system is as follow:
application-
view ->folder (where service_view.php is located)
images -> folder (where myImage.jpg is located)
user_guide-
images ->folder ((where myImage.jpg is located))
Can anyone help me about this? Thanks a lot!
I would suggest storing images in an images folder at the same level as the application folder, instead of trying to mix both PHP code and resources underneath application. Then just link to it like you did to the user guide:
<img src="../../images/myImage.jpg" />
I know more than year has passed since the question was asked but for anyone who comes looking in future, Here is my solution....
I've tried this created a folder images at same level as that of application, in main index.php added a line before last require_once statement.
define('IMAGE_PATH', APPPATH.'../images/');
and used IMAGE_PATH anywhere I wanted to display images.
Hope this helps
I just have an image folder,
domain.com/images
then on the views i just use /images
<img src="<?php echo base_url(); ?>images/image.png" />
and put the images folder outside of the application folder in the same directory
Create an images folder at the same level of the applications folder.
With base_url() you can get the location of your site's base (cfr config).
This is useful because unlike site_url(), you can supply a string to a file, such as an image or stylesheet.
For example:
<img src="<?php echo base_url("/images/icons/stackOverflow.png"); ?>" alt="StackOverflow" title="StackOverflow is the best!" />
This would give you something like: ... src="http://example.com/images/icons/stackOverflow.png" ...
Source: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
it is better practice to upload the images in a folder that is present in the root or the site folder and use base href in the first line of head tag. then the whole page does not need and http path reference. just use the relative path. as codeigniter run using the index.php file in the root, we should use all the relative path w.r.t that index.php page
on local server try this
<img src="http://localhost/ci/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/>
on live use this
<img src="<?php echo base_url();?>/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/>
put a folder on your root directory such as "assets/images/" and the in your code just use it as
<img src="assets/images/imgname.jpg"></img>
Your file structure should be
-applications
-images
-assets
-Or any folder.
Keep the application folder, images folder, and assets folder inside the basic root folder.
Use when you want to include something from your root folder
FCPATH = C:\xampp\htdocs\your_root_folder\
<img src="<?php echo FCPATH; ?>/images/myImage.jpg" />
<img src="<?php echo base_url('/assests/images/image_name.jpg')?>" alt="">
This is the exact path for codeigniter, don't need write the "../../.." just write the path from assets (folder name)(sibling of application).
base_url gives the path of your project folder, not the path of the view folder inside application folder.

Resources