<body bgcolor = "pink">
<form method = "post" action = "" enctype = "mutlipart/form-data">
<input type = "file" name="up" >
<input type = "submit" value = "upload" name="submit">
<input type = "reset" value = "clear">
</form>
<?php
if(isset($_POST['submit']))
{
//echo "<pre>";
//print_r($_FILES);
//echo "</pre>";
$name=addslashes($_FILES['up']['name']);
$image=addslashes($_FILES['up']['tmp_name']);
$image=file_get_contents($image);
$image=base64_encode($image);
echo $image;
$con = mysqli_connect("localhost", "root", "");
mysqli_select_db($con, "pic");
$res = mysqli_query($con , "INSERT INTO image(name, image) VALUES ('$name', '$image')");
if($res)
{
echo "Image uploaded successfully";
}
else
{
echo "Failed to save image in Database";
}
$qry = mysqli_query($con, "SELECT * FROM image");
echo "<table width = 450 border = 5 bordercolor = red align = center bgcolor = green cellpadding = 12>";
echo "<th>Sno</th>";
echo "<th>Name</th>";
echo "<th>Image</th>";
while ($row = mysqli_fetch_row($qry)) {
$src = '<img width = 250 height = 125 src = "data:image; base64, '.$row[2].'">';
echo "<tr>";
echo "<th>".$row[0]."</th>";
echo "<th>".$row[1]."</th>";
echo "<th>".$src."</th>";
echo "</tr>";
}
echo "</table>";
}
?>
</body>
這裏我使用圖片上傳並在表格中顯示,我得到了以下錯誤。如何上傳圖片並使用PHP在網頁中顯示?
- 注意:未定義指數:最多在C:\ WAMP \ WWW \ DMS \ image.php
注:在這裏,我寫PHP和HTML代碼在同一個頁面。
如何來解決這個問題。請幫我
很明顯,你沒有這樣一個索引作爲'陣列中up'。沒有給出這個名字的文件。嘗試'var_dump'文件數組,看看它有什麼。 –
數組(size = 0)爲空。而 var_dump($ _ FILES); – Kiran
不能工作怎麼可能 – Kiran