我现在有一个这样的文件上传程序
这是index.php:
<form action="sendfotos.php" method="post" enctype="multipart/form-data">
Imagem: <input name="imagen" type="file" size="35"> <br />
<input name="submit" type="submit" value="Upload">
</form>
这是sendfotos.php:
<?php
$conexion=mysql_connect("host","user","password")or die("Problemas en la conexion");
mysql_select_db("bdname",$conexion) or
die("Problemas en la seleccion de la base de datos");
$nomimagen= $_FILES['imagen']['name'];
if(move_uploaded_file ( $_FILES [ 'imagen' ][ 'tmp_name' ], '../gallery/user/'.$_FILES [ 'imagen' ][ 'name' ])) {
echo "<link rel='stylesheet' href='adminstyle.css' type='text/css' media='all'><div id='page'><div id='agendasend'><br><br>Midia añadido con exito<br><br><br><a href='fotos.php'>Volver</a></div></div>";
mysql_query("insert into galeriafotos (imagen,id) values
('$nomimagen','$_REQUEST[id]')");
} else{
echo "There was an error uploading the file, please try again!";
}
?>
但现在我需要使用一个多上传程序,哪一个是最好的解决方案?一次上传多个文件,并将每个文件保存在MySQL数据库中。
提前谢谢
最佳答案
创建将上传的文件移动到照片文件夹并将其插入数据库的函数,然后遍历POST接收到的多个文件,并对每个文件调用该函数。这是为了不重复代码。