1

我是新手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>';


?>

如何输入我的图像?

4

1 回答 1

0

首先,$_POST['submit']目前没有做任何事情。其次,上传文件需要您使用$_FILES而不是$_POST.

这应该可以上传所有文件

foreach($_FILES['image'] as $file)
{
    //do something with the data
}

PHP手册:$_FILES
希望这会有所帮助!

于 2013-04-09T14:27:10.290 回答