【发布时间】:2014-05-02 09:52:38
【问题描述】:
好的,这就是我目前所得到的,我能够上传一张图片并将其显示在一个 div 中,但我似乎无法弄清楚如何为加载多张图片做同样的事情。就像上传多张图片并在屏幕上显示所有上传的图片一样。任何帮助表示赞赏,在此先感谢。
另外:我觉得我必须为
设置一个变量$_FILES['image']['name'][0] $_FILES['图像']['名称'][1] 等等
然后做一个forloop把它打印出来?如果我错了,请纠正我?
<?php
// prevent timezone warnings
date_default_timezone_set('America/New_York');
// set the upload location
$UPLOADDIR = "tmp";
// if the form has been submitted then save and display the image(s)
if(isset($_POST['Submit'])){
// loop through the uploaded files
foreach ($_FILES as $key => $value){
$image_tmp = $value['tmp_name'];
$image = $value['name'];
$image_file = "{$UPLOADDIR}{$image}";
// move the file to the permanent location
if(move_uploaded_file($image_tmp,$image_file)){
echo <<<HEREDOC
<div style="float:left;margin-right:10px">
<img src="{$image_file}" alt="file not found" /></br>
</div>
HEREDOC;
}
else{
echo "<h1>image file upload failed, image too big after compression</h1>";
}
}
}
else{
?>
<form name='newad' method='post' enctype='multipart/form-data' action=''>
<table>
<tr>
<td><input type='file' name='image'></td>
</tr>
<tr>
<td><input name='Submit' type='submit' value='Upload image'></td>
</tr>
</table>
</form>
<?php
}
?>
【问题讨论】:
标签: php