我的问题是列表输入文件是动态的,所以这里是代码:
<?php
if(!empty($_FILES)){
$syarat = array('2','3','4','7');
$path = "./uploadtest/";
$jmlsyarat = count($syarat);
for($y = 0; $y<$jmlsyarat; $y++) {
foreach ($_FILES as $file){
$namafile = $syarat[$y].".jpg";
$tmpfile = $file['tmp_name'];
$kefile = $path.$namafile;
move_uploaded_file($tmpfile,$kefile);
}
}
}
?>
<form method="post" enctype="multipart/form-data" action="/uploadtest.php">
<input type="file" name="2" />
<input type="file" name="3" />
<input type="file" name="4" />
<input type="file" name="7" />
<input type="submit" />
</form>
可以使用我在上面创建的动态处理程序来完成吗? 提前谢谢
答案 0 :(得分:0)
这是工作代码(thx to @Federkun):
<?php
if(!empty($_FILES)){
$path = "./uploadtest/";
foreach ($_FILES as $y => $file){
$namafile = $y.".jpg";
$tmpfile = $file['tmp_name'];
$kefile = $path.$namafile;
move_uploaded_file($tmpfile,$kefile);
}
}
?>
<form method="post" enctype="multipart/form-data" action="/uploadtest.php">
<input type="file" name="2" />
<input type="file" name="3" />
<input type="file" name="4" />
<input type="file" name="7" />
<input type="submit" />
</form>
该代码完美无缺!