need your help. I am able to upload image to database on a blob field. Now the question is I am not able to display it back, it just puts out a box with out the real image, what is that I am missing.
Here is the code. images is the field that is declared as blob;
$statement->bind_result($notes, $images, $image_type);
$statement->fetch();
echo $images;
echo '<img rc="data:image/jpeg;base64,'.base64_encode($images).'"/>';
you missed src from img tag. use src in place of rc
echo '<img src="data:image/jpeg;base64,'.base64_encode($images).'"/>';
you missing 'r' in your attribute src <img> tag :
echo '<img src="data:image/jpeg;base64,'.base64_encode($images).'"/>';
Related
I want to be able to hide the img src tag if no image is added from the admin side
I have already tried onerror attribute
This is what I have tried
if ($row['postImage'] !=''){
echo "<p><img src='".$url.$row['postImage']."' class='img-responsive' onerror='this.style.display='none';'></p>";
}
The code above just outputs the following
<img src='https://www.it-doneright.co.uk/blog/images/' class='img-responsive' onerror='this.style.display='none';'>
Update: Got it working with the following code
if ($row['postImage']!='images/' && $row['postImage']!=''){
echo "<p><img src='".$url.$row['postImage']."' class='img-responsive'>
</p>";
}
I think that your postImage field should have a 'null' default value, in that way it will be enough to test for true or false.
Regards.
I have the following url which returns an image in the body, How would I assign that image to a variable so that I could save it or use it within my code?
https://media.licdn.com/dms/image/C4E03AQGOM3p0fHNkwQ/profile-displayphoto-shrink_100_100/0?e=1556755200&v=beta&t=qeQFKYXpev2ZW3hmP1ODDPd3DYPWvl-GaUnPSZG-aQA
The following code returns noting:
<?php
$url = "https://media.licdn.com/dms/image/C4E03AQGOM3p0fHNkwQ/profile-displayphoto-shrink_100_100/0?e=1556755200&v=beta&t=qeQFKYXpev2ZW3hmP1ODDPd3DYPWvl-GaUnPSZG-aQA";
$image = file_get_contents($url);
echo $image;
?>
If you simply want to view an image from a URL, just put that url in the src attribute of an img element like this :
echo '<img src="' . $url . '"/>';
otherwise, if you have to view it from the fetched data of that url, then your question have been answered here:
php: recreate and display an image from binary data (specifically #Krab's answer)
I am using this code to display an image.
echo "<img src=\"".$row["image"]."\">";
Printing $row["image"] gives:
https://www.lesechos.fr/medias/2017/04/19/2080617_hopital-les-candidats-a-la-presidentielle-divergent-sur-les-effectifs-web-0211985257133_300x160.jpg
Which is a valid source when I type it in my browser.
However, no image is displayed... What is wrong?
if you want to show an image, you need to use a img tag. An URL won't be enough. What about :
<?php
echo'<img src=" '.$row["image"].' " alt="my image" />';
/* after edit, I saw that you are using code below */
// echo "<img src=\"".$row["image"]."\">";
// seems fine though
// what about this ->
$path_to_img = $row['image'];
echo "<img src=\"$path_to_img\" alt=\"my image\" />"; /* just added `alt` and last slash to be fully compliant */
?>
what does source inspector show as html output ?
I just tested and hotlinking is fine, imgshows up (kind of an hospital hallway).
you have to print the image url in html src attribute:
echo "<img src='images/." $row['image']. "'/>";
I am getting an image from user and storing it in a folder. Now using the image name i have to search the image in that same folder.The image is stored correctly in the folder.For search i am using some thing like this :
echo '<img src="upload/'.$thumb.'" " />';
the variable $thumb is having the image name.It is getting the image name like that :
$thumb=$_POST['thumbnailPic'];
if(isset($_REQUEST['thumbnailPic'])) {
$thumb=$_REQUEST['thumbnailPic'];
echo '<img src="upload/'.$thumb.'" />';
}
else {
die("no thumbnailPic is found!");
}
I think you have extra quotes in the image src :
echo '<img src="upload/'.$thumb.'" " />';
^---- this is extra quotes
Should be:
echo '<img src="upload/'.$thumb.'" />';
That quotes makes your img tag inavlid. Also check images permission
I have a slideshow set up with Magic fields like the code below, but
now I need each image to have a seperate link. How can I set this up?
I just can't think how I can add this to the code below, I appreciate
any help anyone can offer me.
<div id="slider">
<?php
$images = getFieldOrder('slideshow_slide');
if(is_array($images)){
foreach($images as $image){
echo get_image('slideshow_slide',1,$image);
}
}
?>
</div>
Hooray MagicFields! <3
There are two ways to get an image in MagicFields.
Method 1 will return a full image tag:
echo get_image('slideshow_slide');
Method 2 just returns the url of the image:
echo get_image('slideshow_slide',1,1,0);
In order to generate a link to your full-size image, you'll need to construct an anchor tag using the second method. Maybe something like this:
$image_path = get_image('slideshow_slide',1,1,0);
echo 'Insert link text or thumbnail here';
You might need to modify the above to work with your foreach loop, but that's the basic idea.
Update:
Here's what you need to do. Create another duplicateable text field, called image_url. This field will hold the link for your image. Each image will need a corresponding url. This loop should do what you want:
if(is_array($images)){
foreach($images as $image){
$image_url = get('image_url',1,$image);
echo "<a href='" . $image_url ."'>" . get_image('slideshow_slide',1,$image) . "</a>";
}
}