【发布时间】:2013-11-03 14:52:45
【问题描述】:
我正在尝试在我的系统中进行简单的上传,只需使用 multiple="true" 输入属性。
实际上,我有 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",他只需上传选择的第一张图片。
【问题讨论】:
标签: php mysql forms file-upload