簡體   English   中英

在mysql / phpmyadmin中上傳和顯示圖像

[英]Uploading and Showing Images in mysql/phpmyadmin

我目前正在嘗試創建.php頁面以上傳圖像以存儲在phpmyadmin中的表中。 然后顯示它們。

首先,將圖像添加到數據庫中的表中。 phpmyadmin中的層次結構是:localhost-> images-> Greeting_Cards。

目前,我正在嘗試插入“賀卡”表,因為稍后我將有多個表用於多個類別並分別顯示它們。

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>upload</title> </head> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="file_upload" /> <input type="submit" name="submit" value="upload" /> </form> <?php include '/var/db_file.php'; if(isset($_POST['submit'])) { $conn = mysql_connect("localhost","root", $pass); mysql_select_db("images"); /* Variable inits */ $imageName = $imageData = $imageType = null; $imageName = mysql_real_escape_string($_FILES["image"]["name"]); $imageData = mysql_real_escape_string(file_get_contents($_FILES["image"]["tmp_name"])); $imageType = mysql_real_escape_string($_FILES["image"]["type"]); if(substr($imageType,0,5) == "image"){ mysql_query("INSERT INTO 'Greeting_Cards' VALUES('','$imageName','$imageData')"); echo "Image Uploaded!"; } else{ echo "Has to be an image!"; } } ?> </body> </html> 

上載的圖片不會顯示在表格中。 我正在正確登錄數據庫。 表“賀卡”下的結構是:id(int11),名稱(varchar30)和image(blob)。 在www.mydomainname.net/upload.php上顯示的唯一錯誤/警告是:

注意:未定義的索引:第27行上的/var/www/html/upload.php中的圖像

注意:未定義的索引:第28行的/var/www/html/upload.php中的圖像

警告:file_get_contents():第28行的/var/www/html/upload.php中的文件名不能為空

注意:未定義的索引:第29行的/var/www/html/upload.php中的圖像必須是圖像!

要顯示圖像,我必須首先通過此步驟。 如果發生任何更新,將在此帖子上報告。

修復1:錯誤的名稱:更改為name =“ image”以與php變量參數匹配。 修復2:表名稱的反引號不是單引號。 可選:指定列。

在此先感謝您的幫助!

上傳圖片

<!--?php
include("mysqlconnect.php");

    function GetImageExtension($imagetype)
     {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
           default: return false;
       }
     }



if (!empty($_FILES["uploadedimage"]["name"])) {

    $file_name=$_FILES["uploadedimage"]["name"];
    $temp_name=$_FILES["uploadedimage"]["tmp_name"];
    $imgtype=$_FILES["uploadedimage"]["type"];
    $ext= GetImageExtension($imgtype);
    $imagename=date("d-m-Y")."-".time().$ext;
    $target_path = "images/".$imagename;


if(move_uploaded_file($temp_name, $target_path)) {

    $query_upload="INSERT into 'images_tbl' ('images_path','submission_date') VALUES 

('".$target_path."','".date("Y-m-d")."')";
    mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());  

}else{

   exit("Error While uploading image on the server");
} 

}

?>;

顯示影像

<!--?php
include("mysqlconnect.php");

$select_query = "SELECT 'images_path' FROM  'images_tbl' ORDER by 'images_id' DESC";
$sql = mysql_query($select_query) or die(mysql_error());    
while($row = mysql_fetch_array($sql,MYSQL_BOTH)){

?-->

<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellpadding="5" cellspacing="5">
<tbody><tr>
<td>

<img src="<?php echo $row[" images_path"];="" ?="">" alt="" />">

</td>
</tr>
</tbody></table>

<!--?php
}
?-->

修復1:錯誤的名稱:更改為name =“ image”以與php變量參數匹配。

修復2:表名稱的反引號不是單引號。 可選:指定列。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM