codeigniter image path - image

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.

Related

How to STR Replace and echo in laravel

Files that are uploaded to my site have their names changed and extention change to bin. So for example a uploaded file will be dfd84848.bin, using the bin file worked fine with modelviewer but im trying to test babylon.js and it doesnt work with .bin only if i change .bin to .glb.
This code {{uploaded_asset($detailedProduct->cad_file)}} provides link like uploads/all/p1YZX9TBc7EmimFx4rXnSFKvVor8EttpOUUpylLL.bin
I want to change .bin to .glb and echo it.
i tried this
#php
$previewfile = uploaded_asset($detailedProduct->cad_file);
$replaced = Str::replace('.bin', '.glb', $previewfile );
#endphp
to show i used this <model url="{$replaced}"> but it never echoed url
Edit
So now that it echos as name.glb it doesnt work because the file doesnt exist on server. When 3d models such as .glb, .gltf are uploaded they are renamed to .bin i dont know why. The uploader is AizUploadController.php
To echo a value you should use double curly braces:
<model url="{{ $replaced }}">
Docs: https://laravel.com/docs/8.x/blade#displaying-data

How do I display local image in markdown?

Does anyone know how to display a local image in markdown? I don't want to set up a webserver for that.
I try the following in markdown, but it doesn't work:
![image](files/Users/jzhang/Desktop/Isolated.png)
I suspect the path is not correct. As mentioned by user7412219 ubuntu and windows deal with path differently. Try to put the image in the same folder as your Notebook and use:
![alt text](Isolated.png "Title")
On windows the desktop should be at: C:\Users\jzhang\Desktop
The following works with a relative path to an image into a subfolder next to the document:
![image info](./pictures/image.png)
Solution for Unix-like operating system.
STEP BY STEP :
Create a directory named like Images and put all the images that will be rendered by the Markdown.
For example, put example.png into Images.
To load example.png that was located under the Images directory before.
![title](Images/example.png)
Note : Images directory must be located under the same directory of your markdown text file which has .md extension.
To add an image in markdown file the .md file and the image should be in the same directory. As in my case my .md file was in doc folder so i also moved the image into the same folder. After that write the following syntax in .md file
![alt text](filename)
like ![Car Image](car.png)
This has worked for me.
The best solution is to provide a path relative to the folder where the md document is located.
Probably a browser is in trouble when it tries to resolve the absolute path of a local file. That can be solved by accessing the file trough a webserver, but even in that situation, the image path has to be right.
Having a folder at the same level of the document, containing all the images, is the cleanest and safest solution.
It will load on GitHub, local, local webserver.
images_folder/img.jpg < works
/images_folder/img.jpg < this will work on webserver's only (please read the note!)
Using the absolute path, the image will be accessible only with a url like this: http://hostname.doesntmatter/image_folder/img.jpg
if image has bracket it won't display
![alt text](Isolated(1).png)
rename the image and remove brackets
![alt text](Isolated-1.png)
Update:
if you have spaces in the file path, you should consider renaming it too or if you use JavaScript you can encode it using
encodeURIComponent(imagePath)
Also, always try to save images and files alike with lowercase, please develop that habit, just my personal view though
Adding a local image worked for me by like so: ![alt text](file://IMG_20181123_115829.jpg)
Without the file:// prefix it did not work (Win10, Notepad++ with MarkdownViewer++ addon)
Edit: I found out it also works with html tags, and that is way better:
<img src="file://IMG_20181123_115829.jpg" alt="alt text" width="200"/>
Edit2: In Atom editor it only works without the file:// prefix. What a mess.
Depending on your tool - you can also inject HTML into markdown.
<img src="./img/Isolated.png">
This assumes your folder structure is:
├── img
└── Isolated.jpg
├── README.md
Edited:
Working for me ( for local image )
![system schema](doc/systemDiagram.jpg)
tree
├── doc
  └── jobsSystemSchema.jpg
├── README.md
markdown file README.md is at the same level as doc directory.
In your case ,your markdown file should be at the same level as the directory files.
Working for me (absolute url with raw path)
![system schema](https://server/group/jobs/raw/master/doc/systemDiagram.jpg)
NOT working for me (url with blob path)
![system schema](https://server/group/jobs/blob/master/doc/systemDiagram.jpg)
Just add the relative image file route from the markdown file
![localImage](./client/src/assets/12.png)
This worked for me in ubuntu:
![Image](/home/gps/Pictures/test.png "a title")
Markdown file is in:
/home/gps/Documents/Markdown/
Image file is in:
/home/gps/Pictures/
To my knowledge, for VSCode on Linux, the local image can be normally displayed only when you put the image into the same folder as your .md post file.
i.e. only ![](image.jpg) or ![](./image.jpg) will work.
Even the absolute path like ![](/home/bala/image.jpg)also doesn't work.
In Jupyter Notebook Markdown, you can use
<img src="RelPathofFolder/File" style="width:800px;height:300px;">
Another possibility for not displayed local image is unintentional indent of the image reference - spaces before ![alt text](file).
This makes it 'code block' instead of 'image inclusion'. Just remove the leading spaces.
You may find following the syntax similar to reference links in markdown handy, especially when you have a text with many displays of the same image:
![optional text description of the image][number]
[number]: URL
For example:
![][1]
![This is an optional description][2]
[1]: /home/jerzy/ComputerScience/Parole/Screenshot_2020-10-13_11-53-29.png
[2]: /home/jerzy/ComputerScience/Parole/Screenshot_2020-10-13_11-53-30.png
I've had problems with inserting images in R Markdown. If I do the entire URL: C:/Users/Me/Desktop/Project/images/image.png it tends to work. Otherwise, I have to put the markdown in either the same directory as the image or in an ancestor directory to it. It appears that the declared knitting directory is ignored when referencing images.
Either put the image in the same folder as the markdown file or use a relative path to the image.
just copy the image and then paste it, you will get the output
![image.png](attachment:image.png)
The basic syntax is ![Image description](Any_Image_of_your_choice.png "title"). In my case, I used image name as Any\ Image\ of\ your\ choice.png in ![Image description](Any\ Image\ of\ your\ choice.png) instead of ![Image description](Any_Image_of_your_choice.png) and it was not working. So I would say make sure to check the image directory and also image name doesn't contain spaces if so use underscore(_) instead of space.
Faced issue while using markdown in Jupyter notebook in Ubuntu 18.04.
I got a solution:
a) Example Internet:
![image info e.g. Alt](URL Internet to Images.jpg "Image Description")
b) Example local Image:
![image Info](file:///<Path to your File><image>.jpg "Image Description")
![image Info](file:///C:/Users/<name>/Pictures/<image>.jpg "Image Description")
TurboByte

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')) ?>

Image not retrieve from folder

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

How to find Joomla root directory

how to I find out the Joomla root directory to use in files? I tried the following with no luck:
$path = JPATH_COMPONENT;
//Gives component root
$path = JURI::root();
//Gives absolute path, can't be used for some reason (http://www.site.com)
$path = $_SERVER['DOCUMENT_ROOT'];
//Gives public_html folder, but if someone installs joomla in a directory and not in root, it wrecks the whole thing
Is there a way to find the joomla root of the site only? Thanks.
may be this can help you
http://docs.joomla.org/Constants
Let's say you want to include an image from the images folder, you can simply use this:
$image = JUri::root() . 'images/image_name.png';
JUri::root() and both JUri::site() always define the root directory

Resources