Joomla Php图像查询
我目前在使用joomla插件(Sourcerer)从数据库中用php代码调用图像文件时遇到了问题。但不幸的是,它呼应出许多外来词。我用来回显图像的代码有错误吗 以下是我的示例代码:Joomla Php图像查询,php,joomla,Php,Joomla,我目前在使用joomla插件(Sourcerer)从数据库中用php代码调用图像文件时遇到了问题。但不幸的是,它呼应出许多外来词。我用来回显图像的代码有错误吗 以下是我的示例代码: <?php // Get default database object $db =JFactory::getDBO(); // Get a new JDatabaseQuery object $query = $db->getQuery(true); // Build the query $qu
<?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;
.....
回送到页面后无法设置标题:请使用base64编码图像,而不是
使用base 64编码,并将结果插入img标记中,请参阅:
假设您的代码只保存jpeg图像的文件内容
echo '<img src="data:image/jpeg;base64,'.base64_encode($result->logo).'" />';
echo'徽标)。“/>”;
将产生预期的标记:
<img src="data:image/jpg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAApAAD/7gAOQWRvYmUAZMAAAAAB/9sAhAAMCAgICQgMCQkMEQsJCxEUDwwMDxQXEhIUEhIXFhEUExMUERYWGhsdGxoWIyMmJiMjMjIyMjI4ODg4ODg4ODg4AQwLCwwODA8NDQ8UDg4OFBQPEBAPFBwTExQTExwjGhYWFhYaIyAiHR0dIiAmJiMjJiYwMC4wMDg4ODg4ODg4ODj/wAARCAAQABADASIAAhEBAxEB/8QAaAAAAwEAAAAAAAAAAAAAAAAAAQMEBwEBAQAAAAAAAAAAAAAAAAAAAgMQAAIBAwEJAQAAAAAAAAAAAAECAwARIVExYRIiMmITBAUUEQACAQQDAQAAAAAAAAAAAAABAgMAESES8DFhIv/aAAwDAQACEQMRAD8A0jiINiBnfmio2nU0pWaWFZYupuYBsA9p0qH6P2Y/TjDGKb9IZQPX8bsXBNiFZQUJtkWai9lP1jWqxQvIQsY2LYsOde1//9k="/>
除了这是我网站的徽标之外;-)但我将图像数据作为BLOB存储在数据库中,我是如何检索的?我的代码应该是这样的吗?我用一个例子改进了我的答案我刚刚用粘贴的图像标签测试了一个空文档(第二个)它甚至可以在internet exploder中使用。所以一定是您的图像未经处理,您是如何将其插入数据库的?还可以尝试使用“jpg”和“jpeg”(两者都适用于我!)代码在firefox上运行,但在google chrome上试用时…图片不会显示,但可以保存为图像…这是浏览器的问题吗?从长远来看,您最好使用JDatabaseQuery API,例如,您是否确定在WHERE
和'college'
之间有一个空格?我想您必须这样做,或者您必须这样做可能会出现SQL错误,但仍然使用API将防止出现错误。我的查询没有任何问题,但我从数据库检索到的图像已显示为充满外来词=。=…我该怎么办?