这是我目前的代码,有人能帮我如何上传多个图片与文本在类别?我必须在数据库中以blob的形式存储图像。
<?php
if(count($_FILES) > 0) {
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
mysql_connect("localhost", "root", "");
mysql_select_db ("au");
$cat = $_POST['cat'];
$imgData =addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
$imageProperties = getimageSize($_FILES['userImage']['tmp_name']);
$sql = "INSERT INTO output_images(imageType ,imageData, category)
VALUES('{$imageProperties['mime']}', '{$imgData}', '$cat')";
$current_id = mysql_query($sql) or die("<b>Error:</b> Problem on Image Insert<br/>" . mysql_error());
if(isset($current_id)) {
header("Location: listImages.php");
}
}
}
?>
<HTML>
<HEAD>
<TITLE>Upload Image to MySQL BLOB</TITLE>
<link href="imageStyles.css" rel="stylesheet" type="text/css" />
</HEAD>
<BODY>
<form name="frmImage" enctype="multipart/form-data" action="" method="post" class="frmImageUpload">
<label>Upload Image File:</label><br/>
<input type="text" name="cat">
<input name="userImage" type="file" class="inputFile" />
<input type="submit" value="Submit" class="btnSubmit" />
</form>
</div>
</BODY>
</HTML>
1条答案
按热度按时间h7appiyu1#
我有两篇文章在我的博客提到多个文件上传和存储在mysql数据库的图像。
多个文件上传
上传.html
请注意
'name'
财产<input>
标签应该添加一个数组标签'[]'
. 此外,enctype="multipart/form-data"
应添加在标签中以启用文件上载功能。因此$_FILES
变量可以是一个数组来携带多个文件的信息。然后,product.php转换$文件变量并将文件保存到目标路径。
产品.php
function convert_upload_file_array($upload_files) {
$converted = array();
foreach ($upload_files as $attribute => $val_array) {
foreach ($val_array as $index => $value) {
$converted[$index][$attribute] = $value;
}
}
return $converted;
}
$prod_pic = $mysqli->real_escape_string(file_get_contents($_FILES['prod_pic']['tmp_name']));
$prod_pic_type = $_FILES['prod_pic']['type'];
:
:
$sql = "UPDATE products
SET prod_pic = '{$prod_pic}',
prod_pic_type = '{$prod_pic_type}'
WHERE prod_id = {$prod_id}";
$mysqli->query($sql) or die($mysqli->connect_error);
$mysqli->close();
file_get_contents($_FILES['prod_pic']['tmp_name'])
$mysqli->real_escape_string(......)