由于这个问题,我变得很生气。这是我的数据库:
Cod_Classification int(11)
Cod_App char(10)
ID_eventclass char(5)
Descrizione char(35)
Active char(1)
Logo_Eve blob
我使用这个表格来填充它:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Prova di Upload</title>
</head>
<body>
<form action="UploadImage.php" method="post" enctype="multipart/form-data">
<p>
<label for="ID_evcls">Codice evento</label> <input type="text" name="ID_evcls" maxlength="5" size="10"> <br>
<label for="Desc">Descrizione</label> <input type="text" name="Desc" maxlength="35" size="40"> <br>
Logo da utilizzare: <input name="userfile" type="file" /><br>
<input type="submit" value="Send File" />
<p>
</form>
</body>
</html>
这是 PHP 部分:
<?php
$db_host = "localhost";
$db_user = "USERNAMEDB";
$db_database = "NAMEDATABASE";
$db_password = "*********";
$db_tabeventclassification = "adv_eventclassification";
$ID_ev = $_POST[ID_evcls];
$ID_ds = $_POST[Desc];
$ID_logo = $_FILES['userfile']['name'];
$ID_tmp = $_FILES['tmp_name'];
echo $ID_ev.' '.$ID_ds.' '.$ID_logo.' '.$ID_tmp.'<br><br>';
move_uploaded_file($_FILES['userfile']['tmp_name'], $_FILES['userfile']['name']);
echo '<br><img src="'.$ID_logo.'"><br>';
$datimmagine = file_get_contents($ID_logo);
echo '<br><img src="data:image/jpeg;base64,'.base64_encode($datimmagine).'"><br>';
$connessione = mysql_connect($db_host,$db_user,$db_password);
echo "OK, database is connected<br><br>";
$query='INSERT INTO '.$db_tabeventclassification.' (`Cod_App`, `ID_eventclass`, `Descrizione`, `Active`, `Logo_Eve`) VALUES ("RCWORLDTLV","'.strtoupper($ID_ev).'","'.$ID_ds.'","1","'.addslashes(base64_encode($datimmagine)).'")';
$result = mysql_db_query("AdVisual_02_", $query ,$connessione);
?>
当我启动 html 并上传图像时,我可以在屏幕上完美地看到,如果我使用 PhpMyAdmin,我可以看到带有数据的 blob 字段。但是当我从数据库中检索数据时,我总是有一个损坏的链接图像结果。这里有我为显示数据而构建的应用程序:
<?php
$AdVisualV2MANAGER_ver='0.0030';
echo 'AdVisual V2 Backend Manager Versione '.$AdVisualV2MANAGER_ver.'<br>';
// echo 'Television ID: '.$Host_Cod_App.'<br>';
$db_host = "localhost";
$db_user = $db_prefix."AdVisualV02USR";
$db_database = $db_prefix."AdVisual_02_";
$db_password = "adv2pwpwpw";
$db_tabconfig = "adv_config";
$db_tabpreroll = "adv_preroll";
$db_tabimpressions = "adv_videoimpressions";
$db_tabevents = "adv_events";
$db_tabeventclassification = "adv_eventclassification";
mysql_connect($db_host,$db_user, $db_password);
echo "Connection to the Server opened; Database is ".$db_database." opening result is ".mysql_select_db($db_database)."<br>";
echo "Now listing events<br><br>";
$result = mysql_query("SELECT * FROM ".$db_database.".".$db_tabeventclassification." WHERE `Active` =1");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
echo '<table width="750" border="1">
<tr>
<th width="100" align="center" valign="top"><b>EVENTO</b></th>
<th width="300" align="center" valign="top"><b>DESCRIZIONE</b></th>
<th width="50" align="center" valign="top"><b>LOAD</b></th>
<th width="200" align="center" valign="top"><b>LOGO</b></th>
</tr>';
$numerorighe = mysql_num_rows($result);
for ($i=0;$i<$numerorighe;$i++) {
$riga = mysql_fetch_row($result);
echo '<tr>';
echo '<td align="left" valign="top">'.$riga[2].'</td>';
echo '<td align="left" valign="top">'.$riga[3].'</td>';
$button[i]='<input type="button" id="bt"'.$i.' onclick="LoadJpg('.$i.')" value="Load '.$i.'-->">';
echo '<td align="center" valign="top">'.$button[i].'</td>';
echo '<td align="center" valign="top"> <img src="data:image/jpeg;base64,'.base64_encode($riga[5]).'"></td>';
echo '</tr>';
}
echo '</table>';
?>
<script>
function LoadJpg(scelta)
{
document.write('<input type="file" name="datafile" accept="image/jpeg">');
}
</script>
但是,如果我使用 phpmyadmin 在 blob 字段中手动上传相同的图像,它会完美运行。即使我转储内容,总是使用 phpmyadmin,下载 .bin 文件并将其重命名为 .jpg,它也能正常工作。
问题是,当我使用 phpmyadmin 上传图像时,我看到它将数据转换为十六进制格式,并生成如下 SQL 语句:
UPDATE `AdVisual_02_`.`adv_eventclassification` SET `Logo_Eve` = 0xffd8ffe0001 ...
0acf43a5a97a6089ffd9 WHERE `adv_eventclassification`.`Cod_Classification` = 61;
我能做什么?我哪里错了?从3天开始我就变得疯狂了!!!!!!感谢任何好人会尽力帮助我 ciao