2014-02-28 21 views
0

正常顯示![在這裏輸入的形象描述] [1] HY有我創建了一個上傳信息表..... 我的HTML代碼...圖像不是在MySQL

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Add New Templete</title> 
    <link rel="stylesheet" href="style.css"> 
</head> 
<body> 
    <?php include 'side.php'; ?> 
    <div class="main"> 
    <h2>Add New Templete</h2> 
    <form action="add.php"method="post" enctype="multipart/form-data"> 
     <table border="1px solid"> 
     <tr> 
     <td>Templete Name:</td><td><input type="text" name="temp_name"></td></tr> 
     <tr> 
     <td>Templete Category</td><td><input type="text" name="category"></td></tr> 
     <tr> 
     <td>Templete Image</td><td><input name="MAX_FILE_SIZE" value="102400" type="hidden"><input type="file" name="image"></td></tr> 
     <tr> 
     <td>Templete Discription</td><td><input type="text" name="decp"></td></tr> 
     <tr> 
     <td>Templete Quantity</td><td><input type="text" name="qty"></td></tr> 
     <tr> 
     <td>Templete Price</td><td><input type="text" name="price"></td></tr> 
     <tr> 
      <td></td> 
     <td>  
     <input type="submit" value="ADD"> 
     </td> 
     </tr> 
     </table> 
    </form> 

</div> 
</body> 
</html> 

這裏是將其插入到數據庫中的PHP代碼...

<?php 
include 'connection.php'; 
$name=$_POST['temp_name']; 
$cat=$_POST['category']; 
$image=$_FILES['image']; 
$desc=$_POST['decp']; 
$qty=$_POST['qty']; 
$price=$_POST['price']; 
$qry="INSERT INTO templetes(templete_name,category,image,description,quantity,price)VALUES('$name','$cat','$image','$desc','$qty','$price')"; 
$res=mysql_query($qry,$con); 
if($res) 
{ 

    header('location:product.php'); 
} 
mysql_close($con); 
?> 

現在我想訪問它,並顯示在一個方式的所有信息,我show.php代碼....

<?php 
include 'connection.php'; 
$query = mysql_query("SELECT * FROM templetes"); 
$row = mysql_fetch_array($query); 
$content = $row['image']; 

header('Content-type: image/jpg'); 
    echo $content; 


?> 

但沒有數據被訪問,我的show.php代碼將不起作用,即使它不會顯示我存儲在數據庫中的圖像,而且我的圖像在數據庫中的大小也不正確,意味着圖像的原始大小是40.3kb當它保存在數據庫中時,它的大小僅爲5kb爲什麼?

如何調整圖像大小,同時將其保存到MySQL,像雅虎 輪廓或G +,我們選擇一個圖像爲我們的個人資料,這將適合在 指定的幀。

+0

什麼是你的表結構(例如'顯示創建表templetes的輸出;')? – Gorkk

回答

0

使用:

<?php 
include 'connection.php'; 
$name=$_POST['temp_name']; 
$cat=$_POST['category']; 
$image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); //<== modification 
$desc=$_POST['decp']; 
$qty=$_POST['qty']; 
$price=$_POST['price']; 
$qry="INSERT INTO templetes(templete_name,category,image,description,quantity,price)VALUES('$name','$cat','$image','$desc','$qty','$price')"; 
$res=mysql_query($qry,$con); 

mysql_close($con); // move this here, I think header() function prevents code placed after it to be interpreted. 

if($res) 
{ 

    header('location:product.php'); 
} 

?> 

利用這個來調整圖像:http://php.net/manual/fr/function.imagecopyresized.php

+0

你可以在我的代碼中添加上面的代碼,我可以清楚地理解你的代碼,,, – user2411816

+0

你的答案不錯,圖像存儲但數據不會被訪問?你可以看看我的show.php代碼 – user2411816

+0

添加'stripslashes()'當回聲'$ content':'echo stripslashes($ content);' –