我正在尝试在我的系统中进行简单的上传,只需使用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"
?如果我只是将其更改input
为multiple="true"
,他只需上传所选的第一张图片。