我在提交表单后没有从输入文件中获取任何数据,但是当我删除了try和catch语句时,其他输入能够插入到db中..我在这里做错了什么..
$author = $_SESSION['name'];
$product_image =addslashes(file_get_contents($_FILES['product_image']['tmp_name']));
$imageProperties = getimageSize($_FILES['product_image']['tmp_name']);
try
{
$mysqli->begin_Transaction();
$insert_image = $mysqli->query
("
INSERT INTO product_image
(
author,
regist_date,
fileType,
imageData
)
VALUES
(
'{$author}',
now(),
'{$imageProperties['mime']}',
'{$product_image}'
)"
);
$mysqli->commit();
}
catch (Exception $e)
{
$mysqli->rollback();
}
和我的表格
<form role="form" id="upload_form" method="post" enctype="multipart/form-data">
....
<input name="product_image" type="file" class="inputFile" required >`
....
<input type="submit" value="Submit" class="btnSubmit" />
</form>
答案 0 :(得分:0)
理论上,如果你想将数据提交到同一个php页面,你的代码是有效的。但尝试通过向表单添加操作属性来执行此操作
<form role="form" id="upload_form" action="PageNameHere.php" method="post" enctype="multipart/form-data">