即時通訊使用xampp本地主機開發網站。我想添加圖像使用phpmyadmin,但我不能添加它..圖像可以顯示在phpmyadmin,但不能出現在我的網站..是否有任何問題與我在php編碼?如何使用phpmyadmin在數據庫中插入圖像?
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="MMDB"; // Database name
$tbl_name="artist"; // Table name
// Create connection
$conn = mysqli_connect($host, $username, $password, $db_name);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$Name=$_POST['Name'];
$Hometown=$_POST['Hometown'];
$Income=$_POST['Income'];
$Image=$_POST['Image'];
//file =$_FILES['image']['tmp_name'];
$Video=$_POST['Video'];
$sql = "INSERT INTO $tbl_name(Name, Hometown, Income, Image, Video)
VALUES ('$Name', '$Hometown','$Income','$Image','$Video')";
if (mysqli_query($conn, $sql)) {
include 'admin.php';
} else {
echo "x";
}
mysqli_close($conn);
?>
什麼在文件夾中添加圖像的代碼?
//其中我應該插入這個代碼 「> $圖像= $ _FILES [」 圖像 「] [」 名稱「]; $ UploadedFile的= $ _FILES [ '圖像'] [ 'tmp_name的值']; 如果($圖像){ $文件名=的stripslashes($ _ FILES [ '形象'] [ '名']);
/* Ensure the file is JPG/PNG */
if (($_FILES['image']['type'] != "image/jpg") && ($_FILES['image']['type'] != "image/jpeg") && ($_FILES['image']['type'] != "image/png")) { $error_status = 2; $error_message = "File uploaded was not a JPG or PNG file."; }
else {
/* Ensure the file is less than 10MB */
$size = filesize($_FILES['image']['tmp_name']);
if ($size > (MAX_SIZE * 1024)) { $error_status = 3; $error_message = "File uploaded needs to be less than 10MB."; }
else {
$extension = "jpg";
if(($_FILES['image']['type'] == "image/jpg") || ($_FILES['image']['type'] == "image/jpeg")) { $uploadedfile = $_FILES['image']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); }
else if (($_FILES['image']['type'] == "image/png")) { $extension = "png"; $uploadedfile = $_FILES['image']['tmp_name']; $src = imagecreatefrompng($uploadedfile); }
$img_mime_type = $_FILES['image']['type'];
+1爲問題提供解決方案,而不僅僅是對OP的懲罰。雖然我同意圖像不應該存儲在數據庫中,但如果我希望/必須這樣做並且來找出如何,我想要一個答案 – 2017-05-01 03:55:04