简体   繁体   English

Joomla Php图片查询

[英]Joomla Php Image query

I'm currently having a problem with the image file which i need to call out from the database with php code by using joomla plugin (Sourcerer). 我目前有图像文件的问题,我需要使用joomla插件(Sourcerer)使用php代码从数据库中调出图像文件。 But unfortunately it echo out many alien word. 但不幸的是,它回荡了许多外来词。 Is the code i use to echo out the image have some mistake? 我用来回显图像的代码是否存在一些错误?

Here is my sample code: 这是我的示例代码:

<?php

// Get default database object
$db =JFactory::getDBO();

// Get a new JDatabaseQuery object

$query = $db->getQuery(true);
// Build the query

$query = "

SELECT *

FROM ".$db->quoteName('college')."

WHERE ".$db->quoteName('userid').'='. $db->quote('0123').";

";

// Set the query for the DB oject to execute

$db->setQuery($query);
// Get the DB object to load the results as a list of objects

$results = $db->loadObjectList();

if($results){ 
foreach($results as $result){

echo "<label for='collegeid' class='field prepend-icon'>";
echo "<input type='text' id='collegeid' name='collegeid' class='gui-input' value='$result->collegeid' placeholder='College ID...'>";
echo "<label for='collegeid' class='field-icon'><i class='fa fa-user'></i></label>";

echo "</label>";

echo "</div><!-- end section -->";

echo "</div><!-- end .frm-row section -->";

echo "<div class='section'>";
echo "<label for='collegefullname' class='field prepend-icon'>";
echo "<input type='text' name='collegefullname' id='collegefullname' class='gui-input' value='$result->fullname' placeholder='College's full name...'>";
echo "<label for='collegefullname' class='field-icon'><i class='fa fa-envelope'></i></label>";
echo "</label>";
echo "</div>";

echo "


<div class='section'>
<label for='collegeshortname' class='field prepend-icon'>
<input type='text' name='collegeshortname' id='collegeshortname' class='gui-input' value='".$result->shortname."' placeholder='College's short name...'>
<label for='collegeshortname' class='field-icon'><i class='fa fa-envelope'></i></label> 
</label>
</div><!-- end section -->

<div class='section'>
<label for='description' class='field prepend-icon'>
<textarea class='gui-textarea' id='description' name='description' value='".$result->description."' placeholder='Description...'>".$result->description."</textarea>
<label for='comment' class='field-icon'><i class='fa fa-comments'></i></label>
<span class='input-hint'> 
Please write the description of the college... 
</span> 
</label>
</div><!-- end section -->

<div class='section'>
<h3>Upload College's Logo: </h3><br/>";

header("Content-type: image/jpeg");

echo $result->logo;
.....

The result can be view at here: http://demo.matedis.com/add-and-edit-college 可以在这里查看结果: http : //demo.matedis.com/add-and-edit-college

You cannot set header after you echo to the page: use base64 encoded image rather 回显页面后无法设置页眉:使用base64编码的图像而不是

Use base 64 encoding rather, and insert the result in the img tag, see this answer : 改用base 64编码,然后将结果插入img标签,请参见以下答案

Assuming from your code that you are saving the file content only of jpeg images, 假设您的代码仅保存jpeg图片的文件内容,

echo '<img src="data:image/jpeg;base64,'.base64_encode($result->logo).'" />';

will result in the expected markup: 将导致预期的标记:

<img src="data:image/jpg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAApAAD/7gAOQWRvYmUAZMAAAAAB/9sAhAAMCAgICQgMCQkMEQsJCxEUDwwMDxQXEhIUEhIXFhEUExMUERYWGhsdGxoWIyMmJiMjMjIyMjI4ODg4ODg4ODg4AQwLCwwODA8NDQ8UDg4OFBQPEBAPFBwTExQTExwjGhYWFhYaIyAiHR0dIiAmJiMjJiYwMC4wMDg4ODg4ODg4ODj/wAARCAAQABADASIAAhEBAxEB/8QAaAAAAwEAAAAAAAAAAAAAAAAAAQMEBwEBAQAAAAAAAAAAAAAAAAAAAgMQAAIBAwEJAQAAAAAAAAAAAAECAwARIVExYRIiMmITBAUUEQACAQQDAQAAAAAAAAAAAAABAgMAESES8DFhIv/aAAwDAQACEQMRAD8A0jiINiBnfmio2nU0pWaWFZYupuYBsA9p0qH6P2Y/TjDGKb9IZQPX8bsXBNiFZQUJtkWai9lP1jWqxQvIQsY2LYsOde1//9k="/>

aside from the fact that this is my site's logo ;-) 除了这是我网站的徽标;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM