1

我在解决这个问题时遇到了问题,基本上我有一个带有图像(图像和图像2)字段的表,我正在重用代码并且在提交时可以正常上传联合国图像,但第二个不是上传和关闭当然没有插入到数据库中。

<form action="../imgs/update_code.php" method="post" enctype="multipart/form-data" id="form1">

<input name="image1" type="file" />
<input name="image2" type="file" />

<input name="id" type="hidden" value="<?php echo $row_Recordset1['id']; ?>" />
<input name="submit" type="submit" value="submit" />
</form>

谁能告诉我这是否可以在一次提交中上传到不同的图像,或者我需要继续为每个表单上传一个图像(第一个表单上传/插入“image1”和第二个表单更新/上传“image2”)

<?php require_once('../admin/Connections/cnx.php'); ?>
<?php
ob_start();
$tabla='models';
$destino='../models.php';
mysql_connect($server,$user,$pass);
mysql_select_db($db);
function modificar($tabla,$id){
$strupdate='';
foreach($_POST as $k => $v){
if($k!='imageField_x' && $k!='imageField_y' && $k!='image1' && $k!='image2' &&          $k!='foto2' && $k!='foto3' && $k!='Submit'){
$v=(get_magic_quotes_gpc()) ? $v : addslashes($v);
$strupdate.= "$k='$v',";
}}
$strupdate=substr($strupdate,0,(strlen($strupdate)-1));
mysql_query("SET NAMES utf8");
mysql_query("update $tabla set $strupdate where id='$id'");
}
function reemplazaarchivo($archivo,$archivotemp,$tabla,$campoarchivo,$error,$id){
if($archivo!=''){
$qryant=mysql_query("select * from $tabla where id='$id'");
$rowant=mysql_fetch_array($qryant);
@unlink($rowant[$campoarchivo]);
$extension200=end(explode(".",strtolower($archivo)));
if($extension200!='jpg' && $extension200!='gif' && $extension200!='png' &&  $extension200!='doc' && $extension200!='zip' && $extension200!='pdf' && $extension200!='xls' && $extension200!='ppt' && $extension200!='swf'){
eval($error);exit;}
$foto2=md5(time()).$archivo;
copy($archivotemp,$foto2);
@chmod($foto2,0755);
mysql_query("update $tabla set $campoarchivo='$foto2' where id='$id'");
}
}
modificar($tabla,$_POST['id']);
reemplazaarchivo($_FILES['image1']['name'],$_FILES['image1']['tmp_name'],$tabla,'image1','',$_POST['id']);
for($i=1;$i<4;$i++){
reemplazaarchivo($_FILES['image1'.$i]['name'],$_FILES['image1'.$i]  ['tmp_name'],$tabla,'image1'.$i,'',$_POST['id']);
}
header("Location:$destino");
ob_end_flush();
?>
4

1 回答 1

2

你甚至谷歌? http://php.net/manual/en/features.file-upload.multiple.php

<form action="file-upload.php" method="post" enctype="multipart/form-data">
  Send these files:<br />
  <input name="userfile[]" type="file" /><br />
  <input name="userfile[]" type="file" /><br />
  <input type="submit" value="Send files" />
</form>

另外,您的代码非常不清楚且不安全。请查看安全性。

于 2013-10-10T14:48:32.230 回答