I'm using the lightbox plugin: Fancybox
I wanted to apply lightbox effect on image gallery php file. The image is stored in longblob format instead of folder. Following is the code I did to read image.
<?php
$img_slct=mysql_query("SELECT * FROM news_gallery WHERE news_id='$page[news_id]' ORDER BY position ASC");
while($img=mysql_fetch_array($img_slct))
{ ?>
<img src="load_image.php?id=<?php echo $img['file_id']; ?>"/>
<?php } ?>
load_image.php
$id=$_GET['id'];
$is_file=false;
if(!empty($id))
{
$file=mysql_query("SELECT id FROM news_files WHERE id='$id'");
if(mysql_num_rows($file)>0)
{
$is_file=true;
$file=mysql_fetch_array($file);
}
}
if($is_file)
display_file_news($id);
Everything is displayed correctly but that is an issue when using lightbox to display the image retrieved from longblob database.
<a rel="example_group" href="load_image.php?id=<?php echo $img['file_id']; ?>">
<img src="load_image.php?id=<?php echo $img['file_id']; ?>"/>
</a>
I have no idea how to read the longblob database using lightbox. So I simply put like this --> href="load_image.php?id=<?php echo $img['file_id']; ?>"
I know that is wrong, but can you help me? Please...Let me know if you need more info, because I can't insert all my code at here. Thank you.
Following are my database tables.
news_files table
news_gallery table
Related
Image is successfully fetching from database but it not be shown by the PHP. In place of image it shows a iamge thumbnail.
If I use header('Content-type:image/jpg'); it will show the only thumbnail all page contents disappear.
include 'functions/connect.php';
$user = $_SESSION['email'];
$sql = "SELECT photo FROM user WHERE email='$user'";
$run_sql = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($run_sql);
$user_photo =$row['photo'];
echo"<p><img src='$user_photo'></p>";`
You can try something like this:
<img alt="<?php echo $user_photo; ?>" src="uploads/<?php echo $user_photo; ?>" /> // Upload is folder where image was uploaded
It depends on what the field "photo" contains. If the photo field contains the location of the picture on your system, then the way you have done it should work. However, if the field contains the actual photo in binary format (having field data type as 'blob') then you'll need to do the following:
file_put_contents("image.jpg", $user_photo);
echo "<p><img src='image.jpg' ></p>";
I am facing a problem in showing images in my page using PHP. I have a table "images" in my db. I have saved the names of the images in this table which i am retrieving using PHP. My problem is that the images are not being shown due to unknown logical error. I have given both the absolute and the relative paths of the images in the tag but all in vain. Please suggest me what wrong i am doing in retrieving the code.
My PHP:-
<?php
require_once("includes/database.php");
$img_no = $_GET["img_no"];
$query = "SELECT * FROM `images` WHERE `img_no`=".$img_no;
$result = mysqli_query($con, $query);
?>
HTML:-
<div class="project owl-carousel">
<?php while($row = mysqli_fetch_array($result)){ ?>
<div class="item">
<?php echo "<img class='img-responsive' src='img/".$row['img']."png'> ";?>
</div>
<?php }; ?>
</div>
In the img src, I have given both the absolute and the relative paths of the images folder, but did not work!
Please suggest!
Thanks in advance!
Regards!
Does your image extention(.png) is same to what you have written in your code.
if yes then check whethere you have saved your image name in database with extention or without it.
I am using localhost. I insert image in database blob. I am trying for show image. But I am fail. Image does not show. Database have three field id,name,image. Trying this code.
uimage.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("task_database");
$image=mysql_query("SELECT * FROM image WHERE id=1");
$image=mysql_fetch_assoc($image);
$image=$image['image'];
header("Content-type: image/jpeg");
echo $image;
?>
and using this code in index.php page:
echo "Image Uploaded.<p />Your image:<p /><img src=uimage.php>";
But image did not show. Please help me.
My Full Code here: http://codepad.org/hJ8qucml
The easiest type of handling images in PHP-based websites is to save the images with the its id as name in a separated folder and just saving the id in database!
i really recommend you this type of working with images!
These are quick examples and you should validate any data being passed that is being used in a query. Check out Mysqli.
Using inline base64 encoding:
<?php
mysql_connect("localhost","root","");
mysql_select_db("task_database");
$result=mysql_query("SELECT name, myimg FROM image WHERE id=1");
$image=mysql_fetch_row($result);
$imagesrc=$image[1];
echo '<img src="data:image/jpeg;base64,'.base64_encode($imagesrc).'"/>';
Using PHP file to call the image:
<img src="image.php?id=<?php echo $id; ?>" />
image.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("task_database");
$result=mysql_query("SELECT name, myimg FROM image WHERE id=1");
$image=mysql_fetch_row($result);
$imagesrc=$image[1];
header('Content-Type: image/jpeg');
echo $imagesrc;
?>
I am trying to use a PHP Query to get an image name from my MSSQL table column. The queried image name is put into an <img> tag. If the column is empty, it should set the empty column to the image noimageishereforgbmtrailerserviceltd999.png, which is a blank .png image and make the link unclickable. I am doing this to essentially hide the image from the user if there is no image set, so the user doesn't see a big X inside of where an image should be. The code currently changes the column to noimageishereforgbmtrailerserviceltd999.png correctly, but does not change the css styles of the link around it. Here is the PHP code I'm using:
$job_posname = "SELECT * FROM new_trailers1 WHERE orderid = '$sn'";
$query=mssql_query( $job_posname, $connection);
$array=mssql_fetch_assoc($query);
$job_posname7=stripslashes($array['photo1']);
if ($job_posname7['photo1']===NULL || ctype_space($job_posname7['photo1'])){
$job_posname7 = "noimageishereforgbmtrailerserviceltd999.png";
echo "<script>document.getElementById('picca2').style.pointer-events='none';</script>";
echo "<script>document.getElementById('picca2').style.cursor='default';</script>";
} else {
$job_posname7=stripslashes($array['photo1']);
}
?>
<a id="picca2" href="unitimages/<? echo $job_posname7; ?>" onclick="swap(this); return false;"><img id="pica2" src="unitimages/<? echo $job_posname7; ?>" width=50 height=50></a>
Thank you for any help. All help is appreciated.
Can't you default the noimageishereforgbmtrailerserviceltd999.png on all columns, and just change it if the image exists on the database? I am assuming you are generating the columns dynamically.
Or, just add a class on a PHP variable if the condition is set.
Make a .class in css and just call it depending on what you need.
For example
$job_posname = "SELECT * FROM new_trailers1 WHERE orderid = '$sn'";
$query=mssql_query( $job_posname, $connection);
$array=mssql_fetch_assoc($query);
$job_posname7=stripslashes($array['photo1']);
if ($job_posname7['photo1']===NULL || ctype_space($job_posname7['photo1'])){
$job_posname7 = "noimageishereforgbmtrailerserviceltd999.png";
echo "<script>document.getElementById('picca2').style.pointer-events='none';</script>";
echo "<script>document.getElementById('picca2').style.cursor='default';</script>";
$my_css_class_that_hides_image = "hide";
} else {
$job_posname7=stripslashes($array['photo1']);
}
?>
<a id="picca2" href="unitimages/<? echo $job_posname7; ?>" class="<? echo $my_css_class_that_hides_image; ?>" onclick="swap(this); return false;"><img id="pica2" src="unitimages/<? echo $job_posname7; ?>" width=50 height=50></a>
... And define it on your style sheet:
.hide{
/** Style here **/
}
I create a component in my joomla website. the component shows some photos (not big, only 8KB). the photos are stored in mysql blob. i can upload the photos to the joomla database but i cannot display it on the website. whatever i do it only show some encoding character or blank. I tried to create a separate page but but the result is same. Here is what i have done :
mycomp is my joomla component.
admin.mycomp.php
<?php
function showDetail($option)
{
$db = &JFactory::getDBO();
$id = mysql_real_escape_string(JRequest::getVar('id'));
$query = "select id,myphoto from jos_myphotos where id = ".$id;
$db->setQuery($query);
$rows = $db->loadObjectList();
HTML_myphoto::showPhoto($rows,$option);
}
?>
admin.mycomp.html.php
<?php
class HTML_myphoto
{
...
function showPhoto($row,$option)
{
...
header("Content-type: image/jpeg");
echo $row->myphoto; //this will show some encoding character
echo base64_decode($row->myphoto); //this will show blank page
//change echo with print get the same result.
...
}
...
}
I tried to create a separate page like this :
admin.mycomp.html.php
<?php
class HTML_myphoto
{
...
function showPhoto($row,$option)
{
...
?>
<img src="show_image.php?myphoto=<?php echo $row->myphoto;?>" width=200 height=300>
<?php
...
}
...
}
show_image.php
<?php
$myphoto = (isset($_GET['myphoto'])) $_GET['myphoto'] : false;
if($myphoto)
{
header("Content-type: image/jpeg");
echo $myphoto; //this will show some encoding character
echo base64_decode($myphoto); //this will show blank page
//change echo with print get the same result.
}
?>
the result is same.
I think you have 2 options:
Either you make an image tag with its source in a PHP file receiving only a ID parameter and retrieving the photo's string in the DB and echoing it.
Or you echo directly your photo's string in your tag:
<img src="<?php echo base64_decode($myphoto); ?>" />
EDIT
I just checked in an old app where I store the favicons in a DB. You don't need to base64_decode when you display your image inline (my option 2).
So FYI, this image works:
<img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAQAAAAEABcxq3DAAACkElEQVQ4y42TTWyUZRSFn/e+n6W00E4l9ScSCZGODXFLIIZENyZu1ITEGBdE3ejGVQksunDlwoUrE0ICCQuomZAYF4YNNvEPlFpjiJRgKq10HDKdmVJxEOh0vu+9h0UrMSyAk9zVOffczXPRI8hdciVNTZ/X6MjLOnrkK3XTLbk64lEK5FIhaf87HyqznYKy5qsLyuUPL/D1OXzkC8U4IhhViC9o7OAnSkkKksQDVG81GR//iAvTbS7OXIQQ1p0Oc3O/YlCAAAcSQIHIEc43Z8/z6r5xfrsiBp9+ArK4FgprNye//oEMDIJDMBDU6jc4d/YXzpz5kcuzC5SGBvBkoMT257ah5FTn/4Qgpqd+InM3LEDr+j8cO/45pyrnmLk0w0uv7KV/cIDCI4GIhUAgY3h4C9W5Kma9LF//l2xpqc33301xcuJLTp+ehLiJbSNlcpxoEanAolF4okB0lRAiuVOt1cje/+AAly8tcHWhDnEDeAfXKo/FTbg7ZLdwCrDI0PAAK7fvQATkYIbN/l4jWh8pAb4BrJ/abI32301MXULKoIhE9bKxt8RKJ4D1gXpIitj+d19j6PGN7CiXQavgHYir3G5fY+tT/Wx/cgulnh6su0JYvUPodiHvAGJz32YoJC222qo1lvTH1b906NBngq06cPBjFZKkXIuNmhZbN3RlvqUTlUnt2fumsGc0NvapkJLcpeRrzF+r31R5dLd2PP+i6s3if//gcndJUqPRUKVSUbPZFCnlkpJcSWmd+dffeE/BntWJk9/eW7q/RJJSSjIzQxKBhIUcgN17dhFCxsREheXlZSStZUIghEBRFACYGRlwz3Q5FuDtt/Yx/fMFSqVB8jwnrPP/Xy7LMtwdM+Mu+2gfA7SP0igAAAAASUVORK5CYII=" style="margin-right: 5px; vertical-align: middle;" class="bbns_itemDragger">
And it is stored in my DB like this (base64 encoded):
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAQAAAAEABcxq3DAAACkElEQVQ4y42TTWyUZRSFn/e+n6W00E4l9ScSCZGODXFLIIZENyZu1ITEGBdE3ejGVQksunDlwoUrE0ICCQuomZAYF4YNNvEPlFpjiJRgKq10HDKdmVJxEOh0vu+9h0UrMSyAk9zVOffczXPRI8hdciVNTZ/X6MjLOnrkK3XTLbk64lEK5FIhaf87HyqznYKy5qsLyuUPL/D1OXzkC8U4IhhViC9o7OAnSkkKksQDVG81GR//iAvTbS7OXIQQ1p0Oc3O/YlCAAAcSQIHIEc43Z8/z6r5xfrsiBp9+ArK4FgprNye//oEMDIJDMBDU6jc4d/YXzpz5kcuzC5SGBvBkoMT257ah5FTn/4Qgpqd+InM3LEDr+j8cO/45pyrnmLk0w0uv7KV/cIDCI4GIhUAgY3h4C9W5Kma9LF//l2xpqc33301xcuJLTp+ehLiJbSNlcpxoEanAolF4okB0lRAiuVOt1cje/+AAly8tcHWhDnEDeAfXKo/FTbg7ZLdwCrDI0PAAK7fvQATkYIbN/l4jWh8pAb4BrJ/abI32301MXULKoIhE9bKxt8RKJ4D1gXpIitj+d19j6PGN7CiXQavgHYir3G5fY+tT/Wx/cgulnh6su0JYvUPodiHvAGJz32YoJC222qo1lvTH1b906NBngq06cPBjFZKkXIuNmhZbN3RlvqUTlUnt2fumsGc0NvapkJLcpeRrzF+r31R5dLd2PP+i6s3if//gcndJUqPRUKVSUbPZFCnlkpJcSWmd+dffeE/BntWJk9/eW7q/RJJSSjIzQxKBhIUcgN17dhFCxsREheXlZSStZUIghEBRFACYGRlwz3Q5FuDtt/Yx/fMFSqVB8jwnrPP/Xy7LMtwdM+Mu+2gfA7SP0igAAAAASUVORK5CYII=
I'm sorry, did you skip some lines from show_image.php?!
Cause $myphoto is just the id of the photo. You can't base64_decode an ID.