【发布时间】:2016-10-12 18:05:41
【问题描述】:
我正在尝试通过表单将图像上传到 mysql 这是我的表单
<form action="" method="POST" id="formSettingStoreLogo">
<div>
<p>Put a logo </p><br>
<input type="file" name="logo" />
<input type="submit" name="submitLogo" id="submitLogo" value="Upload" />
</div>
</form>
这是我写的jQuery
$(document).on('submit', '#formSettingStoreLogo', function(e)
{
e.preventDefault();
$.ajax({
type: 'POST',
url: logoupload.php,
data: $("#formSettingStoreLogo").serialize(),
success: function(data)
{
}
});
};
和 logoupload.php
<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
sec_session_start();
$storeid = $_SESSION['storeid'];
$stmt = $mysqli->prepare("UPDATE store_details SET store_logo=? WHERE store_id =?");
$stmt->bind_param('bi',$_POST['logo'],$storeid);
$stmt->execute();
$stmt->store_result();
?>
<p>Uploading logo of store</p>
还有
blob is the data type of store_logo column
表单发布数据但不插入数据库。
【问题讨论】:
-
你不能使用这个ajax调用上传图片来发送你需要使用的文件FileAPI