I'am using codeigniter file upload class to upload images and save full_path in to the database.
But when displaying the images i can't see it.
Here is my code
<?php foreach($images as $img) {?>
<img src="<?php echo $img;?>" width="150">
<?php }?>
From view-source i will open the image link it will mixed with base-url and image full_path.
http://localhost/holiday/admin/profile/package_explained/C:/xampp/htdocs/holiday/uploads/package-images/img-holoday-sample.png
the value of $img is (ie fullpath of the image) C:/xampp/htdocs/holiday/uploads/package-images/img-holoday-sample.png.
How can i display image with full_path?
Only get image name form Controller. Do not track full path.
Bcz your host server doesn't have path like this C:/xampp/htdocs/
<?php foreach($images as $img)
{
?>
<img src="<?php echo base_url()?>uploads/package-images/<?php echo $img;?>" width="150">
<?php
}
?>
Assume that you are not saving the path like that you have mentioned in DB:
Try this (add http:// before print):
<?php foreach($images as $img) {?>
<img src="http://<?php echo $img;?>" width="150">
<?php }?>
Related
I have the following code
<figure>
<?php if ($data[$i]->thumbnail) { ?>
<img src="<?php echo $img ?>" width="465" height="300" alt="news-report-juli19" title="" />
<?php } ?>
</figure>
I want to display images from mysql database dynamically,
the image_field_name=thumbnail.
I have 10 records in db and all have different images.
You should have to given the image path as well when you want to display.
<?php if ($data[$i]->thumbnail) { ?>
<img src="<?php echo base_url('path_of_img/$img'); ?>" width="465" height="300" alt="news-report-juli19" title="" />
<?php } ?>
If you use the Codeigniter framework, please try this.
In controller
$data['images'] = $this->model->get_images();
$this->load->view('view_name', $data);
In model you should make get_images() method that get image urls.
In view
<?php
foreach ($images as $value) {
echo '<img src="'.$value['thumbnail'].'" width="465"
height="300" alt="news-report-juli19" title="" />';
}
?>
Good luck.
use query variale with db colmn where images are present
use this in source img src
echo $query_variable['db_coln_name']
The file path is:
theme
assets
src
images
grey-arrow.svg
Markup:
<?php $getIcon = get_template_directory().'/assets/src/images/grey-arrow.svg';?>
<div><img src="<?php echo $getIcon; ?>"/></div>
<?php echo $getIcon;?>
The image doesn't load and an echo of $getIcon returns:
/var/www/html/wp-content/themes/theme/assets/src/images/grey-arrow.svg
... Which is the correct path. Ideas on why the image doesn't load?
You should echo it and also you are closing your php tag properly.
<img src="<?php echo get_template_directory_uri(); ?>/assets/src/images/grey-arrow.svg"/>
or you can use bloginfo which is easier to remember and use (You need not echo)
<img src="<?php bloginfo('template_url'); ?>/assets/src/images/grey-arrow.svg"/>
How do I properly echo images combining HTML and PHP? $offer['picture'] has link saved as example.com/picture.png. I've tried many different options, but nothing works. Can anyone help me out?
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
?>
<img src="<?php echo $image ?>">
<?php
}
If there is only example.com/picture.png in $offer['picture'], problem is that images linked incorrectly. You should add http:// before image link to make browser sure you are loading image by absolute path.
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
?>
<img src="http://<?php echo $image ?>">
<?php
}
Well it depends on your directory structure.
suppose your images are in example.com/assets/images/photo-1.jpg
your code should be
<?php foreach($json['offers'] as $offer) {
$image = $offer['picture']; ?>
<img src="http://www.example.com/assets/images/<?php echo $image; ?>">
<?php } ?>
In fact, you need to concatenate or hard code the path and image name will be appended dynamically.
Try this syntax,
<?php
foreach($json['offers'] as $offer) {
$image = $offer['picture'];
echo "<img src='$image' />";
}
?>
I'm trying to create a simple image gallery that displays thumbnails of uploaded images. Once a thumbnail is clicked, I would like to be directed to a page with the large version of the image, along with a comment section. So basically I'm trying to do something similar to deviantart. What I have now looks something like this:
<a href="<?php echo $image->large_image_path; ?>">
<img src="<?php echo $image->thumbnail_image_path; ?>"></a>
Clicking on a thumbnail will take to me to the large image path, which is not really what I want. Any help is greatly appreciated.
You must make the href="<?php echo $image->large_image_path; ?>" to somehing like href="show_image.php?image_path=<?php echo $image->large_image_path; ?>"
In show_image.php you can den get the path of the image by $_REQUEST['image_path'], and add it into the code like this:
<img src="<?php echo $_REQUEST['image_path']; ?> />
The you can add information or styling around the bigger image.
So, link to a PHP page instead of the image. Even better, put the image path in to a database, and use the image id to get the path and information of the image. Like this:
href="show_image.php?image_id=<?php echo $image->id; ?>"> and then in show_image.php, given that you have a method for getting the image:
<?php $image = GetImage($_REQUEST['image_id']); ?>
<img src="<?php echo $image->large_image_path; ?> />
<?php echo $image->description; ?>
<?php echo $image->date; ?>
Hope this helps you on the way.
I am trying to display image from a blob field of a MySQL table. Looks like I have some sort of error in the following line. As soon as I put "header("Content-type: image/jpeg")" things get messed up and instead of displaying webpage, all source code of the page is displayed.
Please let me know how to correct.
<div class="image" align="left">
<a href="<?php header("Content-type: image/jpeg"); echo $rec['image']; ?>">
<img src="<?php echo $rec['image']; ?>" width="150" border="0"/>
</a>
</div><!-- image -->
You normally don't put the actual image contents in the src= attribute of the image tag. Instead, you point to the URL of an image file.
(There are ways to include the image source directly in the HTML, but it doesn't work consistantly with all browsers, and you still won't have your <a> link working properly.
Instead, the best way to do this is to create a separate PHP file to serve the image.
Your HTML:
<div class="image" align="left">
<img src="myimage.php?key=<?php echo($key) ?>" width="150" border="0"/>
</div><!-- image -->
myimage.php:
<?php
header("Content-type: image/jpeg");
$key = $_GET['key'];
// todo: load image for $key from database
echo $rec['image'];
You're trying to put the image data inline inside the content. The only feasible way to do this is via a Data URI data URI. Something like:
<img src="data:image/jpeg;base64,<?= base64_encode($rec['image']) ?>" width="150" border="0" />
However, what you probably want to do is put it into a separate script. So your HTML would be:
<img src="showimage.php?id=XXX" width="150" border="0" />
And your showimage.php script would be:
<?php
// Get $rec from database based on the $_GET['id']
header('Content-Type: image/jpeg');
echo $rec['image'];
?>
I've done something like that retrieving blob from my database in another way that you may find useful, here is the code example.. see if it suits your needs and if you needed anymore help let me know.
while ($row = mysql_fetch_array($hc_query2)) {
$title = $row['title'];
$text = $row['text'];
$image = $row ['image'];
$output ='<div class="HCInstance"><img src="data:image/jpeg;base64,' . base64_encode($image) . '" alt="High Council" width="100px" height="100px"/>
<div class="HCHeader"><h2>'.$title.'</h2></div><br/><div class="HCDetails"><p>'.$text.'</p></div></div>';
echo $output;
}