圖像沒有被插入到mysql中。來自Ajax FAIL響應即將到來。下面 我試圖通過Ajax插入圖像。但查詢沒有執行
<?php
include "db.php";
//keep your db name
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
//you keep your column name setting for insertion. I keep image type Blob.
$query = "INSERT INTO images (id,image) VALUES(0,'$image')";
$qry = mysqli_query($con,$query);
if($qry){
echo "success";
}else{
echo "fail";
}
?>
<html lang="en">
<head>
<title>PHP - Image Uploading with Form JS Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" >
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
$(document).ready(function() {
$(".upload-image").click(function(){
\t $(".form-horizontal").ajaxForm({target: '.preview'}).submit();
});
});
</script>
</head>
<body>
\t <nav class="navbar navbar-default">
\t \t <div class="container-fluid">
\t \t <div class="navbar-header">
\t \t <a class="navbar-brand" href="#">PHP - Image Uploading with Form JS Example</a>
\t \t </div>
\t \t </div>
\t </nav>
\t <div class="container">
\t <form action="ajax_php_file.php" enctype="multipart/form-data" class="form-horizontal" method="post">
\t \t <div class="preview"></div>
\t \t <input type="file" name="image" class="form-control" style="width:30%" />
\t \t <button class="btn btn-primary upload-image">Save</button>
\t </form>
\t </div>
</body>
</html>
表====
代碼給出這裏是表
DROP TABLE IF EXISTS live_your_life
。 images
; CREATE TABLE live_your_life
。 images
( id
INT(10)無符號NOT NULL DEFAULT '0', image
團塊, PRIMARY KEY(id
) )ENGINE = InnoDB的默認字符集= LATIN1;
任何幫助將不勝感激!
嘗試在你的表中添加自動增量: http://dev.mysql.com/doc/refman/5.7/en/example-auto-increment.html –