I have this problem when I read a picture from the database.
It shows like this:
This my code:
<?php
include 'Header.php';
include 'yzd.php';
?>
<div class="container">
<h1> All Project </h1>
<?php
$posts = mysqli_query($db_connect,"select * from Project order by id desc");
while($post = mysqli_fetch_array($posts)){
echo "
<article>
<a href='Project.php?id=$post[id]'>
<h1>$post[NameProject]</h1>
</a>
<p class='text-muted']>
<h3>$post[TypeProject]</h3>
</p>
<h4>$post[Description]</h4>
$post[Pic];
<p>-----------------------------------------------------------------------------</p>
</article>";
}
?>
[![enter image description here][2]][2]
Try converting the raw image output into a base 64 data URI (see here)
you may be able to do this by changing
$post[Pic]
into
<img src='".'data:image/png;base64,' . base64_encode($post["Pic"])."'/>
Given all of the images in your databases are stroed as png(s) The type may need to be varied dependent on image type.
Please in the future use code snippets and not screenshots.
Related
I'm using Owl Carousel to create a carousel gallery of logos. I'm using Advanced Custom Field's repeater feature to grab all of the urls of the logos. Here's the markup for the gallery:
<div id="clients">
<?php
$clients = get_field('client_carousel');
$client_logo = get_field('client_logo');
if( $clients ) {
?>
<section>
<div id="owl-clients" class="owl-theme owl-carousel">
<?php foreach( $clients as $client_logo ): ?>
<div class="item">
<img class="featurette-image img-responsive center-block" src="<?php echo $client_logo['url']; ?>" alt="<?php echo $client_logo['alt']; ?>"></div>
<?php endforeach; ?>
</div>
</section>
<?php } ?>
</div><!--end clients-->
The repeater field name is client_carousel and the field name of the field within it is client_logo.
I have a working demo here. It recognizes the seven logos in the group, but the only thing I can't get is the url for the img src.
Couple things to note. You're overriding the $client_logo variable, so not sure if that was just an abandoned artifact in the code since it doesn't look like you use it anyhow:
$client_logo = get_field('client_logo');
<?php foreach( $clients as $client_logo ): ?>
Other thing is ACF repeater field allows you to choose the output of the field type "image" - assuming that's what you set for the "url" field. Now, suppose you set "url" as an image, you can then select the output as Image URL instead of the default Image Array if you want the raw URL returned.
Supposing that's how you set it, then it should give you the image url without having ot modify your code:
<?php echo $client_logo['url']; ?>
However, we don't know the architecture of your repeating field and without that knowledge we wouldn't be able to advise further. Update your post and I can update this answer if this info doesn't point you in the right direction.
In this little snippet of code ,i show how i take the "foto1" column of my database and transfer the value of it to a variable in c# named $foto.
The $foto contains the path of the image corresponding to the product that is showing up. Ive tried to copy and paste the path and ditch out the php part and it works. But when i put it in img src it gives me like the broken image thing.And i cant figure out why it does that.
All help is aprecciated .
Have a nice day :)
<div class="row shop_box-top">
<?php
$ligaBD=odbc_connect('basededadospap','','');
$sql="SELECT * FROM produto WHERE nome_produto LIKE '%ADIDAS%'";
$resultado=odbc_exec($ligaBD,$sql);
?>
<div class="row shop_box-top">
<?php
while (odbc_fetch_row($resultado))
{
$nome = odbc_result($resultado,2);
$preco= odbc_result($resultado,4);
$foto = odbc_result($resultado,9);
?>
<div class="col-md-3 shop_box"><a href="stansmithflatwhite.html">
<img src="<?php echo $foto; ?>" class="img-responsive" alt=""/>
<span class="new-box">
<span class="new-label">Novo</span>
</span>
<div class="shop_desc">
<h3><?php echo $nome; ?></h3>
<span class="actual"><?php echo $preco; ?></span><br>
</div>
</a></div>
<?php }?>
depends of what path contains the $foto var. If is the absolute path, you have to retrive the relative path.
Try also to append an / or an http[s] in front of the path
<img src="/<?php echo $foto;?>">
So it would be : //path/to/photo
As I can see it in your comment, your image paths contain spaces, so a possible solution can be to use urlencode() before echoing them.
Try passing full path to img tag like http://localhost/xyz/images/Cal�ado/Adidas/Homem/Stan Smith/ADIDAS STAN SMITH - RED/ch-adidas-stan-smith-red-5.jpg.
Replace "localhost/xyz" with your website directory path.
I have a basic upload + Gallery view for pictures. thanks to a recent question i asked i have arranged them by date. However i am now having trouble displaying the pictures the right way up i.e. landscape/portrait.
PHP code:
<?php
$sql="SELECT * FROM chiseldonuploads ORDER BY id DESC";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
<img class="photos" src="uploads/<?php echo $row['file'] ?>">
<?php
}
?>
</div>
Current View of the Images
Thanks in advance
I am currently creating a CMS.
Currently I have.
* Saved my images in mysql as app_image
* Saved the images as a URL to where the images are located
But creating MY INDEX PAGE only displays my link as a broken URL.
my code for this page:
<?php
include_once('include/connection.php');
include_once('include/article.php');
$article = new article;
$articles = $article->fetch_all();
?>
<html>
<head>
<title>testing</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
CMS
<ol>
<?php foreach ($articles as $article) { ?>
<li>
<a href="article.php?id=<?php echo $article['app_id']; ?>">
<img src="<?php echo $article['app_image']; ?>" height"100" width"100">
<?php echo $article['app_title']; ?>
</a> -
<small>
Posted: <?php echo date('l jS', $article['article_timestamp'] ); ?>
</small></li>
<?php } ?>
</ol>
<br><small>admin</small>
</div>
</body>
</html>
Can anyone see how I have gone wrong?
Thanks.
OK, I have done simalar thing and it is working just fine.
The code looks similar, and looks fine by me, now, maybe the link indeed is broken (maybe you didn't input the right upload link in DB)
I would go step by step and check that link (check if it is the right link). (with /path/name.ext)
If it is some help here is my case:
I put in DB post_id,post_title,post_contents, post_link
than i get that info with:
$query = $db->prepare ("SELECT bla bla FROM bla bla ORDER BY id DESC")
$query->execute();
$query->bind_result(everything that is selected seperated with ",");
(including $link)
<?php
while($query->fetch()):
?>
<a href="single-post.html" title="">
<img src="../images/<?php echo $link; ?>">
</a>
<?php
}
?>
NOW, the trick I did (to avoid problem is that i put inside DB only the name of file, the upload path is stored directly in HTML ("../images/")
Your code looks similar, and I think it should work, I think the problem is with link.
Var dump can come to the rescue here. Try this to see what the array key values should be set to for each of the elements in $article.
<?php foreach ($articles as $article) { ?>
echo '<pre>'; //just makes it a bit easier to read
var_dump($article); exit;
This is my PHP script which displays a radio station's schedule:
<div class="divider"></div>
<div class="main" style="width:552px;">
<img src="$image" width=115 height=60>
<div class="time">$airtime</div>
<div class="show"><h3><a href="$link><b>$presenter</b></a></h3>
<p>$showdesc</p></div>
<div class="footer"></div>
</div>
</div>
<div class="footer"></div>
<div class="bottom"></div>
</div>
The values with the dollar sign represent the field names in my database, which is radiopresenters.
How would I get this to work as a PHP script, and display the values from the database?
All values in the fields are stored in TEXT format, apart from the image field which is stored in BLOB format.
Airtime is stored in a separate database entitled as radioschedule which has all 4 fields ib, and I intend to link these together via some relational means.
What's the best way to get it to display as the above, especially the BLOB part?
What you want to do is set up an show_image.php script, Example
show_image.php
<?php
$id = (isset($_GET['blid']) && is_numeric($_GET['blid'])) (int)$_GET['blid'] : false;
if($id)
{
if(false !==($res = mysql_query('SELECT blob_data FROM table WHERE blob_id = ' . $id))
{
$data = mysql_fetch_assoc($res);
header("Content-type: image/jpg"); //Send the content Type here.
print $data['blob_data'];
exit;
}
}
?>
Then within your html files you would do the follwing.
<div class="divider"></div>
<div class="main" style="width:552px;">
<img src="show_image.php?id=<?php echo (int)$id?>" width=115 height=60>
<div class="time">$airtime</div>
<div class="show">
<h3><a href="$link><b>$presenter</b></a></h3>
<p>$showdesc</p></div>
<div class="footer"></div>
</div>
</div>
<div class="footer"></div>
<div class="bottom"></div>
That's roughly how its done, another pointer is when your selecting your data via your main page, you should not select the blob data as it will slow your application down, and show_image.php may require more work as its for example purposes only
Peace.
You could write the image stored as a blob in the database out to a file. You could then use a url as your image source.
Assuming $presenter doesn't have any file/url reserved characters in it, and $image is stored as an accurate binary jpg (or png or gif etc.) , you could do:
<?php
if($fh = fopen("/webroot/images/{$presenter}.jpg", "wb")) {
fwrite($fh, $image) ;
fclose($fh) ;
}
?>
<img src="/images/<? echo $presenter ; ?>.jpg" width="115" height="60">
I would suggest that you work out some way of caching the file, so it doesn't have to be written out for every page load though.
Are you asking how to put those values into your file?
As for the text ones you could just use
<?=$airtime?>
or if your server setup doesn't support short tags just use
<?php echo $airtime?>
I would just do this inline with your php.
Example:
<div class="time"><?=$airtime?></div>
As for the BLOB, I would advise not doing this and just storing the image on your server and store the image file's name in the db. BUT if you are intent on doing this I think the only way you can do this is by having a separate script that returns an image file. Something like this:
<?php
// Do all your db stuff here, grab the blob file. Probably from a $_GET paramater
$image = $row['image'];
header("Content-type: image/jpeg"); // or gif, etc...
echo $image;
die();
?>
Then in your other file you would do something like:
<img src="imagescript.php?person_id=<?=$person_id?>" width=115 height=60>