【发布时间】:2012-03-19 14:51:43
【问题描述】:
我需要修改一张图片上传表单,以便我可以上传多张图片(确切地说是 6 张)。我尝试添加另一个输入并按照其他人的建议更改名称值,但它仍然显示与第一个输入复制的相同图像。我知道这可能很简单,但我不是 PHP 开发人员,所以我一直无法找到解决方案。
上传图片的代码如下:
if(isset($_FILES['image']) && $_FILES['image']['tmp_name'] != '') {
$tempext = explode('.', $_FILES['image']['name']);
$tempext = strtolower($tempext[count($tempext) - 1]);
switch($tempext) {
case 'jpg':
case 'jpeg':
$ext = '.jpg';
break;
default:
$ext = false;
}
if($ext != false && move_uploaded_file($_FILES['image']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/img/profiles/' . $id . $ext)) {
$imagesuccess = chmod($_SERVER['DOCUMENT_ROOT'] . '/img/profiles/' . $id . $ext, 0644) ? 'yes' : 'no';
} else {
$imagesuccess = 'no';
}
}
对于输入:
<div class="control-container<?php if((isset($_FILES['image']) && !empty($_FILES['image']['name']))) echo ' error'; ?>">
<label for="image">Large Image</label>
<div class="multifield">
<?php
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/img/profiles/' . $id . '.jpg')) {
echo '<img src="/img/profiles/' . $id . '.jpg?' . rand() . '" width="310px" />';
}
?>
<input type="file" name="image" id="image" />
</div>
</div>
任何帮助将不胜感激。
谢谢
【问题讨论】: