我是Web编程的初学者,正在开发一个简单的购物网站,在我的控制管理员中,我有用来处理产品页面操作(例如添加,显示以及编辑和更新)的页面 当我添加产品时,它具有图像作为数据库中的列之一 一切正常,但是当我上传图像时,仍然显示图像损坏 像这样: this is the image
这是我用于显示图像的php代码:
<?php
/*
*/
$product = 'active';
if (isset($_SESSION['A_Username'])) {
include 'init.php';
$do = isset($_GET['do']) ? $_GET['do'] : 'Manage';
// Start Manage Page
if ($do == 'Manage') { // Manage Page
$stmt = $con->prepare("SELECT
*
FROM
product
ORDER BY
P_ID ASC");
// Execute The Statment
$stmt->execute();
// Assign To Variable
$Product = $stmt->fetchAll();
if (!empty($Product )) {
?>
<div class="site-content">
<h1 class="text-center">Products Page</h1>
<div class="container">
<div class=" table table-striped table-hover ">
<table class="main-table text-center table table-bordered">
<tr>
<td>#ID</td>
<td> Image</td>
<td>Product name</td>
<td>Product Descritption</td>
<td>Price</td>
<td>Control</td>
</tr>
<?php
foreach ($Product as $product ) {
echo "<tr>";
echo "<td>" .$product['P_ID'] . "</td>";
echo "<td>" ;
echo'<img src="data:image/jpeg;base64,.base64_encode'.($product['image'] ).'" height="60" width="75" class="img-thumbnail""/>';
echo "</td>";
echo "<td>" .$product['name'] . "</td>";
echo "<td>" .$product['descr'] . "</td>";
echo "<td>" .$product['price'] . "</td>";
echo "<td>
<a href='product.php?do=Edit&adid=". $product['P_ID']."' class='btn btn-success'><i class='fa fa-edit'></i> Edit </a>
<a href='product.php?do=Delete&adid=". $product['P_ID']."' class='btn btn-danger confirm'><i class='fa fa-close'></i> Delete </a> ";
echo "</td>";
echo "</tr>";
}
?>
</table>
<a href="product.php?do=Add" class="btn btn-primary"> <i class="fa fa-plus"></i> Add new product</a>
</div>
</div>
</div>
这是添加图像时的代码:
} elseif ($do == 'Insert') { // Insert Items Page
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<div class="site-content">';
echo '<h1 class="text-center">Add Product</h1>';
echo '<div class="container">';
// Get Variables From The Form
$file = $_FILES['image']['name'];
$name = $_POST['name'];
$desc = $_POST['desc'];
$price = $_POST['price'];
// Insert To The Database With This Info
$stmt = $con->prepare("INSERT INTO
product(image, name, descr,price)
VALUES(:zimage, :zname, :zdescr, :zprice) ");
$stmt->execute(array(
'zimage' => $file,
'zname' => $name,
'zdescr' => $desc,
'zprice' => $price,
));
// Echo Success Message
$theMsg = '<div class="alert alert-success"> <strong>'. $stmt->rowCount() . '</strong> Record Inserted </div>';
redirectHome($theMsg, 'back');
}
} else {
echo "<div class='container'>";
$theMsg = '<div class="alert alert-danger">Sorry You Cant Browse This Page Directly</div>';
redirectHome($theMsg, 'back');
echo "</div>";
}
我希望有人能帮助我,我会为他感恩