我是新手php
,想询问有关使用name="image[]"
. 这是我的代码:
HTML
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="image[]" multiple="multiple"/>
<input type="submit" name="submit"/>
</form>
PHP
<?php
$table_name ="posts";
$_POST['submit'];
$title = $_POST['title'];
$cat_id = $_POST['cat_id'];
$date = date('Y-m-d', strtotime($_POST['date']));
$description = mysql_real_escape_string($_POST['description']);
$status = $_POST['status'];
$sql = "INSERT INTO $table_name (title,cat_id,date,description,status) VALUES ('$title','$cat_id','$date','$description','$status')";
$result = mysql_query($sql);
$sqlImage = mysql_fetch_array(mysql_query("SELECT id FROM $table_name ORDER BY id DESC "));
$parentId = $sqlImage['id'];
foreach ($_POST['image'] as $images) {
$resImage = mysql_query("INSERT INTO media (parent_id,image) VALUES ('$parentId','$images') ");
}
$_SESSION['add_content'] = true;
echo ' <script>location.href="'.$base_url.''.$table_name.'"</script>';
?>
如何输入我的图像?