我已成功上传了一张图片,但多张图片出现问题。 如何上传第二张图片?我是否在数据库中创建一个新字段并将其命名为photo02,然后再输入另一个名为photo2的表单输入。如何更改目标以上传和移动两个文件?
表格
Photo: <input type="file" name="photo" multiple>
Photo: <input type="file" name="photo" multiple>
守则
$target = "upload/";
$target = $target . basename( $_FILES['photo']['name']);
$pic=($_FILES['photo']['name']);
mysql_query("INSERT INTO `employees` VALUES ('$pic' )") ;
if(move_uploaded_file($_FILES ['photo'] ['tmp_name'], $target))
{
require_once 'SimpleImage.php';
$image = new SimpleImage();
$image->load($target);
$image->resize(50,50);
$image->save($target);
输出
echo '<b> Picture 1: </b>','<img src="/upload/' . $row->photo . '" border=1>';
echo '<b> Picture 2: </b>','<img src="/upload/' . $row->photo . '" border=1>';
答案 0 :(得分:0)
钻取是相同的,你只需要输入一个多属性:
<input type="file" name="photo" multiple>
然后$ _FILES数组将包含更多图片。
您可以使用print_r($ _ FILES);
查看它答案 1 :(得分:0)
在数组$ _FILES上使用foreach
if(isset($_FILES ['uploaded_files']))
{
**foreach($_FILES['uploaded_files']['name'] as $key=>$value)**
{
if(is_uploaded_file($_FILES['uploaded_files']['tmp_name'][$key]) && $_FILES[['uploaded_files']['error'][$key] == 0)
{
$filename = $_FILES['uploaded_files']['name'][$key];
$filename = time().rand(0,999).$filename;
if(move_uploaded_file($_FILES['uploaded_files']['tmp_name'][$key], 'uploads/'. $filename))
{
echo 'The file '. $_FILES['uploaded_files']['name'][$key].' was uploaded successful';
}
else
{
echo 'There was a problem uploading the picture.';
}
}
else
{
echo 'There is a problem with the uploading system.';
}
}
}
?>