0

我正在尝试在我的系统中进行简单的上传,只需使用multiple="true"input 属性。实际上,我有 15 个文件输入,它们都将文件名重命名为:'id.in.the.bd'_'number'.jpg(例如:65_1.jpg)。像这样:

HTML

    // inside a form
    <?php for ($x = 1; $x <= 15; $x++) { ?>
       <input name="foto_<?php echo $x; ?>" type="file" id="foto" multiple="true" />
    <?php } ?>

PHP

if ($_GET['action'] == "insert") {


//sql insert


// do a consult to find the $id
$sql = mysql_query("SELECT * FROM imoveis ORDER BY id DESC LIMIT 1", $link); 

$result = mysql_fetch_array($sql, MYSQL_ASSOC);
$id = $result['id'];

for ($x = 1; $x <= 15; $x++) {
   $file = $_FILES["foto_" . $x];
   $path = '../../images/galeria/' . $id . '_' . $x . '.jpg';
   move_uploaded_file($file["tmp_name"], $path);
}

如何轻松更改我的代码以使用multiple="true"?如果我只是将其更改inputmultiple="true",他只需上传所选的第一张图片。

4

1 回答 1

1

将输入标签更改为

<input name="foto[]" id="foto_1" type="file" />

在 PHP 中,这些文件可以通过 $_FILES['foto']['name'] 数组访问,如下所示:

$_FILES['foto']['name'][0] for file 1
$_FILES['foto']['name'][1] for file 2

ETC..

于 2013-10-24T18:32:53.017 回答