我一直在尝试使用以下代码上传文件流,
<form enctype="multipart/form-data" action="carousel_update.php?id=<?php echo $id;?>" method="post">
for($j = 1 ; $j <= $n ; $j++) {
echo "<option value='$j'>$j</option>";
}
echo "</td></tr>
<tr><td>Title:</td><td><input type=\"text\" name=\"title[$i]\"></td></tr>
<tr><td>Image: </td><td><input type=\"file\" name=\"picture$i\"></td></tr>
<tr><td>Description:</td><td><textarea name=\"description[$i]\"></textarea></td></tr>
<tr><td>Link Text: </td><td><input type=\"text\" name=\"link_text[$i]\"></td></tr>
<tr><td>Link URL: </td><td><input type=\"text\" name=\"link_url[$i]\"></td></tr>
<tr><td>Link Target: </td><td><input type=\"text\" name=\"link_target[$i]\"></td></tr></table></fieldset>";
}
}
?>
<input type="submit" value="Submit">
在动作文件 carousel_update.php 中,
for($i = 1; $i<=$n ; $i++) {
$file = "picture".$i;
$order = $_POST['order'][$i];
$title = $_POST['title'][$i];
$description = $_POST['description'][$i];
$linktext = $_POST['link_text'][$i];
$linkurl = $_POST['link_url'][$i];
$linktarget = $_POST['link_target'][$i];
$target = dirname(__FILE__). "/images/".$_FILES[$file]["name"];
if(move_uploaded_file($_FILES[$file]["tmp_name"], $target)) {
echo "Uploaded";
}
else {
echo "Problems in uploading file";
}
}
如果我必须上传 3 个文件,我可以上传一些图像,但其他图像显示错误。我检查了服务器日志,它说:
[Tue Aug 20 12:00:35 2013] [error] [client 127.0.0.1] PHP Notice: Undefined index: picture2 in /var/www/akai/carousel_update.php on line 19, referer: http://127.0.0.1/akai/update_carousel.php?id=1
[Tue Aug 20 12:00:35 2013] [error] [client 127.0.0.1] PHP Notice: Undefined index: picture2 in /var/www/akai/carousel_update.php on line 21, referer: http://127.0.0.1/akai/update_carousel.php?id=1
[Tue Aug 20 12:00:35 2013] [error] [client 127.0.0.1] PHP Notice: Undefined index: picture3 in /var/www/akai/carousel_update.php on line 19, referer: http://127.0.0.1/akai/update_carousel.php?id=1
[Tue Aug 20 12:00:35 2013] [error] [client 127.0.0.1] PHP Notice: Undefined index: picture3 in /var/www/akai/carousel_update.php on line 21, referer: http://127.0.0.1/akai/update_carousel.php?id=1
我不知道 mu 代码中的错误是什么。提前致谢。