上载多个图像文件并显示在下一页上.PHP


Upload multiple image files and display on the next page. PHP

我试图一次上传多个图像,然后在提交时在页面上显示这些图像。这将用于mPDF。我正在使用手册中的示例http://mpdf1.com/manual/index.php?tid=467

它有一个文本框和一个图像上传器,并在下一页显示文本框中的内容和图像。如何将其转换为使用多个图像?

第1页:

<?php
$html = '
<html>
<body>
<form action="example_userinput2.php" method="post" enctype="multipart/form-data">
Enter text:
<br />
<textarea name="text" id="text"></textarea>
<br />
<label for="file">Choose Image to upload:</label> <input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
';
echo $html;
exit;
?>

第2页:(也更具体地说,在允许多个图像后,我更改了我标记的区域***。)

<?php
if (($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg")
& $_FILES["file"]["size"] < 20000)   {
// If the destination file already exists, it will be overwritten
move_uploaded_file($_FILES["file"]["tmp_name"], "../tmp/" . $_FILES["file"]["name"]);
}
else {
echo "Invalid file";
}
$html ='
<html>
<body>
<div>'.$_POST['text'].'</div>
**<img src="' ."../tmp/" . $_FILES["file"]["name"].'" />**
<form action="example_userinput3.php" method="post" enctype="multipart/form-data">
<textarea style="display:none" name="text" id="text">'.$_POST['text'].'</textarea>
**<input type="hidden" name="filename" id="filename" value="'. $_FILES["file"]**["name"].'" />
<input type="submit" name="submit" value="Create PDF file" />
</form>
</body>
</html>
';
echo $html;
exit;
?>

第3页转到mPDF生成器,这样我就可以将其转换为PDF,用于我心目中的另一个项目。

任何帮助都会很棒。

从php手册中,可以在此处找到:http://php.net/manual/en/features.file-upload.multiple.php

   <form action="example_userinput2.php" method="post" enctype="multipart/form-data">
      Send these files:<br />
      <input name="userfile[]" type="file" /><br />
      <input name="userfile[]" type="file" /><br />
      <input type="submit" value="Send files" />
    </form>

在第2页,您可以继续循环并一次处理这些文件:

foreach ($_FILES['array_of_files'] as $position => $file) {
    // should output array with indices name, type, tmp_name, error, size
    var_dump($file);
}

您可以执行与循环中的一个文件相同的操作

您可以在页面上设置多个<input type="file"> html元素,设置方式如下:

<input type="file" name="file[0]" />
<input type="file" name="file[1]" />

等等。

然后在PHP中循环它们:

foreach($_FILES['file'] as $file){
    //refer to everything as $file instead of $_FILES['file']
} 

这应该足以让你开始。